-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoDisableSound.py
114 lines (77 loc) · 3.02 KB
/
AutoDisableSound.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import obspython as obs
from time import sleep
import os
sourcename = ""
audiofolder = ""
testfile = ""
wasplaying = False
# ------------------------------------------------------------
def script_description():
return "Automatically disables a Media Source once it has finished playing a sound and clears the filename\n\nBy TheAstropath"
def play_task():
global wasplaying
if not is_source_playing():
if wasplaying:
hidesource()
wasplaying = False
else:
wasplaying = True
def is_source_playing():
source = obs.obs_get_source_by_name(sourcename)
mediastate = obs.obs_source_media_get_state(source)
#obs.script_log(obs.LOG_DEBUG, "Media state: "+str(mediastate))
obs.obs_source_release(source)
return mediastate == 1 #PLAYING is 1
def script_update(settings):
global sourcename
sourcename = obs.obs_data_get_string(settings, "sourcename")
hidesource()
unsetfilename()
def script_load(settings):
obs.script_log(obs.LOG_DEBUG, "Loading script")
hidesource()
unsetfilename()
obs.timer_add(play_task,100)
def script_unload():
#obs.timer_remove(server_handle)
hidesource()
unsetfilename()
obs.script_log(obs.LOG_DEBUG, "Unloading script")
def hidesource():
#obs.script_log(obs.LOG_DEBUG,"Trying to hide source "+sourcename)
frontendscenes = obs.obs_frontend_get_scenes()
#obs.script_log(obs.LOG_DEBUG,str(frontendscenes))
for scenesource in frontendscenes:
#obs.script_log(obs.LOG_DEBUG,str(scenesource))
#scenesource = obs.obs_frontend_get_current_scene()
scene = obs.obs_scene_from_source(scenesource)
#obs.script_log(obs.LOG_DEBUG,"Scene "+str(scene))
sceneitem = obs.obs_scene_find_source(scene,sourcename)
if sceneitem:
#obs.script_log(obs.LOG_DEBUG,"Scene item "+str(sceneitem))
obs.obs_sceneitem_set_visible(sceneitem,False)
#obs.obs_source_release(scenesource)
obs.source_list_release(frontendscenes)
def unsetfilename():
source = obs.obs_get_source_by_name(sourcename)
#obs.script_log(obs.LOG_DEBUG,"Source "+str(source))
settings = obs.obs_source_get_settings(source)
#obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings)))
obs.obs_data_set_string(settings,"local_file","")
#obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings)))
obs.obs_source_update(source,settings)
obs.obs_data_release(settings)
obs.obs_source_release(source)
def set_source_speed(source,speed):
settings = obs.obs_source_get_settings(source)
speedpct = int(speed*100)
obs.obs_data_set_int(settings,"speed_percent",speedpct)
obs.obs_source_update(source,settings)
obs.obs_data_release(settings)
def script_defaults(settings):
global sourcename
sourcename= ""
def script_properties():
props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "sourcename", "Media Source Name", obs.OBS_TEXT_DEFAULT)
return props