55
66obs = obslua
77
8- source_name = " "
8+ source_name_text = " "
99format_playing = " "
1010format_paused = " "
1111interval = 1
12+ source_name_browser = " "
1213
1314function update_text (source )
1415 local result = spotify ()
1516 local text = " [Spofity not running]"
17+ local artwork = " "
1618 if result ~= " " then
1719 result = split (result , " , " )
1820 local paused = (result [1 ] == " paused" )
1921 local format = paused and format_paused or format_playing
2022 text = format :gsub (" {n}" , result [2 ]):gsub (" {a}" , result [3 ])
23+ artwork = result [4 ]
2124 end
2225
2326 local settings = obs .obs_data_create ()
24- obs .obs_data_set_string (settings , " text" , text )
27+ if obs .obs_source_get_id (source ) == ' browser_source' then
28+ obs .obs_data_set_string (settings , " url" , artwork )
29+ -- obs.obs_data_set_string(settings, "width", 640)
30+ -- obs.obs_data_set_string(settings, "height", 640)
31+ else
32+ obs .obs_data_set_string (settings , " text" , text )
33+ end
2534 obs .obs_source_update (source , settings )
2635 obs .obs_data_release (settings )
36+
2737end
2838
2939function timer ()
30- local source = obs .obs_get_source_by_name (source_name ) -- > obs_source_t
31- if source ~= nil then
32- local current_scene_source = obs .obs_frontend_get_current_scene () -- > obs_source_t
33- local current_scene = obs .obs_scene_from_source (current_scene_source ) -- > obs_scene_t
34- local scene_item = obs .obs_scene_find_source_recursive (current_scene , source_name ) -- > obs_sceneitem_t
35-
36- if (scene_item ~= nil ) and obs .obs_sceneitem_visible (scene_item ) then
37- update_text (source )
40+ for i , source_name in ipairs ({source_name_text , source_name_browser }) do
41+ local source = obs .obs_get_source_by_name (source_name ) -- > obs_source_t
42+ if source ~= nil then
43+ local current_scene_source = obs .obs_frontend_get_current_scene () -- > obs_source_t
44+ local current_scene = obs .obs_scene_from_source (current_scene_source ) -- > obs_scene_t
45+ local scene_item = obs .obs_scene_find_source_recursive (current_scene , source_name ) -- > obs_sceneitem_t
46+
47+ if (scene_item ~= nil ) and obs .obs_sceneitem_visible (scene_item ) then
48+ update_text (source )
49+ end
50+ obs .obs_source_release (current_scene_source )
3851 end
39- obs .obs_source_release (current_scene_source )
52+ obs .obs_source_release (source )
4053 end
41- obs .obs_source_release (source )
4254end
4355
4456function restart_timer (settings )
45- source_name = obs .obs_data_get_string (settings , " source_name " )
57+ source_name_text = obs .obs_data_get_string (settings , " source_name_text " )
4658 format_playing = obs .obs_data_get_string (settings , " format_playing" )
4759 format_paused = obs .obs_data_get_string (settings , " format_paused" )
4860 interval = obs .obs_data_get_int (settings , " interval" )
61+ source_name_browser = obs .obs_data_get_string (settings , " source_name_browser" )
4962
5063 obs .timer_remove (timer )
5164 obs .timer_add (timer , interval * 1000 )
@@ -55,7 +68,13 @@ function spotify()
5568 local cmd = " osascript -e " .. [[ '
5669 if application "Spotify" is running then
5770 tell application "Spotify"
58- return {the player state, the name of the current track, the artist of the current track}
71+ return {¬
72+ the player state, ¬
73+ the name of the current track, ¬
74+ the artist of the current track, ¬
75+ the artwork url of the current track, ¬
76+ (the player position) / (the (duration of the current track) / 1000) ¬
77+ }
5978 end tell
6079 else
6180 error "Spotify not running."
@@ -83,29 +102,35 @@ function script_description()
83102 <h2>Spotify Mac</h2>
84103 <h4>Display Now Playing Track Info</h4>
85104 <p>{n} = Name {a} = Artist</p>
86- <p style="font-size: 11pt;"><i><a href="https://github.com/RayPS/obs-spotify-mac">version 1.1 </a></i></p>
105+ <p style="font-size: 11pt;"><i><a href="https://github.com/RayPS/obs-spotify-mac">version 1.2 </a></i></p>
87106 </center></body></HTML>]]
88107end
89108
90109function script_properties ()
91110 local props = obs .obs_properties_create ()
92111
93- local p = obs .obs_properties_add_list (props , " source_name" , " Text source" , obs .OBS_COMBO_TYPE_EDITABLE , obs .OBS_COMBO_FORMAT_STRING )
112+ local list_text = obs .obs_properties_add_list (props , " source_name_text" , " Text Source" , obs .OBS_COMBO_TYPE_EDITABLE , obs .OBS_COMBO_FORMAT_STRING )
113+ obs .obs_properties_add_int (props , " interval" , " Update Interval (s)" , 1 , 60 , 1 )
114+ obs .obs_properties_add_text (props , " format_playing" , " Playing Format" , obs .OBS_TEXT_DEFAULT )
115+ obs .obs_properties_add_text (props , " format_paused" , " Paused Format" , obs .OBS_TEXT_DEFAULT )
116+ obs .obs_properties_add_text (props , " info_text_artwork" , " Artwork Image (640×640):" , obs .OBS_TEXT_INFO )
117+ local list_browser = obs .obs_properties_add_list (props , " source_name_browser" , " Browser Source" , obs .OBS_COMBO_TYPE_EDITABLE , obs .OBS_COMBO_FORMAT_STRING )
118+
94119 local sources = obs .obs_enum_sources ()
95120 if sources ~= nil then
96121 for _ , source in ipairs (sources ) do
97122 source_id = obs .obs_source_get_unversioned_id (source )
98123 if source_id == " text_gdiplus" or source_id == " text_ft2_source" then
99124 local name = obs .obs_source_get_name (source )
100- obs .obs_property_list_add_string (p , name , name )
125+ obs .obs_property_list_add_string (list_text , name , name )
126+ elseif source_id == " browser_source" then
127+ local name = obs .obs_source_get_name (source )
128+ obs .obs_property_list_add_string (list_browser , name , name )
101129 end
102130 end
103131 end
104132 obs .source_list_release (sources )
105133
106- obs .obs_properties_add_int (props , " interval" , " Update Interval (s)" , 1 , 60 , 1 )
107- obs .obs_properties_add_text (props , " format_playing" , " Playing Format" , obs .OBS_TEXT_DEFAULT )
108- obs .obs_properties_add_text (props , " format_paused" , " Paused Format" , obs .OBS_TEXT_DEFAULT )
109134 return props
110135end
111136
118143
119144function script_update (settings )
120145 print (" script_update" )
121- if source_name ~= nil then
146+ if source_name_text ~= nil then
122147 restart_timer (settings )
123148 else
124- print (" source_name not set" )
149+ print (" source_name_text not set" )
125150 end
126151end
0 commit comments