Skip to content

Commit 8143f43

Browse files
committed
Add lua script
1 parent 3fbaed1 commit 8143f43

File tree

4 files changed

+114
-26
lines changed

4 files changed

+114
-26
lines changed

BrowserImageSlideshow.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!--
22
3-
BrowserImageSlideshow v1.1
3+
BrowserImageSlideshow v1.2
44
https://github.com/dustymethod/BrowserImageSlideshow
5+
https://obsproject.com/forum/threads/random-image-slideshow.110157/
56
67
-->
78
<div id="imageContainer"></div>
@@ -48,7 +49,7 @@
4849
images.pop();
4950
for (let i = images.length-1; i >= 0; i--) {
5051
// remove js, sh, or directory
51-
let remove = images[i].includes(".js") || images[i].includes(".sh") || !images[i].includes(".");
52+
let remove = images[i].includes(".js") || images[i].includes(".sh") || !images[i].includes(".") || images[i].includes(".git");
5253
if (remove) {
5354
images.splice(i, 1);
5455
}

README.txt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
1-
BrowserImageSlideshow v1.1
1+
BrowserImageSlideshow v1.2
22
https://github.com/dustymethod/BrowserImageSlideshow
3+
Discussion & support: https://obsproject.com/forum/threads/random-image-slideshow.110157/
34

4-
A local browser source for OBS that plays images in random or alphabetical order. Has no image count limit.
5+
A local browser source for OBS that plays images in random or alphabetical order.
6+
Displays each image exactly one per loop.
57

68
Modes (settings.js)
7-
0: Random order (default). Displays each image exactly once per loop.
9+
0: Random order
810
1: Alphabetical order
9-
2: Alphabetical order (start at random image)
11+
2: Alphabetical order (start at random image when source becomes visible)
1012

1113
Setup
1214
0. Download: click "Clone or download" from the github page, choose "Download ZIP", and unzip the files.
13-
1. In OBS Studio or Streamlabs OBS:
15+
- save the zip somewhere in your Documents folder, and not in the default obs-plugins folder.
16+
1. Add the browser source in OBS:
1417
- Add Source > Browser
15-
- Add local file "BrowserImageSlideshow.html"
18+
- Choose local file "BrowserImageSlideshow.html"
1619
- Remove Custom CSS
17-
- Check "Shutdown source when not visible" and "Refresh browser when scene becomes active"
18-
2. Place your images in the "images" folder. jpg, png, gifs all work.
19-
3. Refresh images - This must be done whenever images are added or renamed!
20-
- Run RefreshImagesW.cmd (for windows) or RefreshImages.sh (for linux)
20+
- Enable "Shutdown source when not visible" and "Refresh browser when scene becomes active" options.
21+
2: Add the lua script:
22+
- Tools > Scripts
23+
- Add RefreshImagesLua.lua. Select the script to view settings.
24+
3. Place slideshow images in the "images" folder. jpg, png, gifs all work.
25+
4. Refresh images/settings
26+
- This must be done whenever images are added/removed/renamed, or when settings are updated.
27+
- OBS > Tools > Scripts: select script & press Reload scripts button
2128
- Refresh the source in OBS by toggling its visibility
22-
4. *** Repeat step 3 whenever you add or rename images, or they won't appear! ***
29+
5. *** Repeat step 4 whenever you add/remove/rename images or update the settings. ***
30+
2331

2432
Notes
25-
- settings.js can be opened & edited in notepad. (includes slide duration & mode settings)
26-
- To use updated settings, refresh source by toggling visibility
27-
- The RefreshImages script saves a list of all images in the images folder in "images.js"
33+
- Adding RefreshImageLua.lua to OBS is optional. if not used, the list of images needs to be updated
34+
manually by running RefreshImagesW.cmd (windows) or RefreshImages.sh (linux)
35+
- settings.js can be opened & edited manually in any text editor. (includes slide duration & mode settings)
36+
- updating settings thru RefreshImagesLua.lua will overwrite settings.js
2837
- Filenames with uncommon characters may not display
38+
- OBS's slideshow currently preloads all slideshow images, and has a 250MB limit.
39+
This browser source doesn't preload images, and has no 250MB limit.
2940

30-
Discussion & support: https://obsproject.com/forum/threads/random-image-slideshow.110157/
41+
Issues
42+
- because of the way script(s) write to a file, a harmless command window will pop up briefly when the script is run.
43+
Haven't found a way to suppress this yet.

RefreshImagesLua.lua

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--[=====[
2+
3+
v1.2
4+
https://obsproject.com/forum/resources/random-image-slideshow.852/
5+
https://github.com/dustymethod/BrowserImageSlideshow
6+
7+
--]=====]
8+
9+
obs = obslua
10+
11+
mode = 0
12+
slideDuration = 3800
13+
imageCount = 0
14+
defaultSlideDuration = 4000
15+
minSlideDuration = 1000
16+
maxSlideDuration = 100000
17+
18+
function script_description()
19+
return "Script for the slideshow browser source. Saves a list of images in images/images.js, and saves settings in settings.js. See README for full details. " ..
20+
"Is run automatically when OBS is launched.\n\n" ..
21+
22+
"*** Whenever settings or images are updated, reload the script & refresh the browser to use updated settings/images: \n"..
23+
"- Reload script: press the reload button with this script selected.\n"..
24+
"- Refresh browser source: toggle the source's visiblity off and on\n"..
25+
26+
"\nModes: \n" ..
27+
"0: Random order\n" ..
28+
"1: Alphabetical order\n" ..
29+
"2: Alphabetical order (start at random image when source becomes visible)"
30+
end
31+
32+
function script_properties()
33+
props = obs.obs_properties_create()
34+
obs.obs_properties_add_int(props, "mode", "Mode:", 0, 2, 1)
35+
obs.obs_properties_add_int(props, "slideDuration", "Slide duration (ms):", minSlideDuration, maxSlideDuration, 500)
36+
return props
37+
end
38+
39+
-- called when script is loaded
40+
function script_load(settings)
41+
obs.obs_data_set_default_int(settings, "slideDuration", defaultSlideDuration)
42+
refresh_images()
43+
end
44+
45+
-- called when script settings change
46+
function script_update(settings)
47+
mode = obs.obs_data_get_int(settings, "mode")
48+
slideDuration = obs.obs_data_get_int(settings, "slideDuration")
49+
update_slideshow_settings()
50+
end
51+
52+
-- write settings to js file
53+
function update_slideshow_settings()
54+
local output = assert(io.open(script_path() .. 'settings.js', "w"))
55+
56+
output:write('let mode = '.. mode .. ';\n')
57+
output:write('let slideDuration = '.. slideDuration .. ';\n')
58+
output:close()
59+
end
60+
61+
-- write list of images to js file
62+
function update_image_list(dir)
63+
local output = assert(io.open(script_path() .. 'images/images.js', "w"))
64+
local files = assert(io.popen('dir "'..dir..'" /b'))
65+
output:write('let imageNamesStr=`\n')
66+
imageCount = 0
67+
68+
for line in files:lines() do
69+
output:write(line .. "\n")
70+
imageCount = imageCount + 1
71+
--print(line)
72+
end
73+
74+
files:close()
75+
output:write('`')
76+
output:close()
77+
end
78+
79+
function refresh_images()
80+
local list = update_image_list(script_path() .. 'images/')
81+
print("Refreshed images (images: ".. imageCount .." | mode: ".. mode .." | duration: ".. slideDuration .. ")")
82+
end

settings.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
// duration in ms
2-
let slideDuration = 3800;
3-
4-
// modes:
5-
// 0 (default): random order. Displays each image exactly once per loop.
6-
// 1: Alphabetical order
7-
// 2: Alphabetical order (start at random image)
81
let mode = 0;
9-
10-
/* Don't forget to refresh the source in OBS after changing the settings! */
2+
let slideDuration = 4000;

0 commit comments

Comments
 (0)