-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpselect.py
More file actions
executable file
·63 lines (56 loc) · 2.06 KB
/
pselect.py
File metadata and controls
executable file
·63 lines (56 loc) · 2.06 KB
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
#!/usr/bin/env python3
import subprocess
import json
import urllib.parse
import sys
import random
def get_coconut_list():
cmd = ["coconut.py", "list"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
raise Exception("Error: {}".format(err))
out_str = out.decode("utf-8", errors="ignore")
return json.loads(out_str)
def filter_coconut(coconuts):
return [c for c in coconuts if c.get("exists")]
if __name__ == "__main__":
coconuts = get_coconut_list()[::-1]
coconuts = filter_coconut(coconuts) # rm non-existent coconuts
imageUrls = [c["imageUrl"] for c in coconuts]
selected_coconut = None
selected_index = None
if "--play" in sys.argv or "-p" in sys.argv:
selected_image_url = random.choice(imageUrls)
else:
cmd = ["image_selector2.py"] + imageUrls
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
raise Exception("Error: {}".format(result.stderr))
selected_image_url = result.stdout.strip()
for i, c in enumerate(coconuts):
if c["imageUrl"] == selected_image_url:
selected_coconut = c
selected_index = i
break
if not selected_coconut or selected_index is None:
raise Exception(
"Error: No coconut found for image URL {}".format(selected_image_url)
)
rotated_coconuts = coconuts[selected_index:] + coconuts[:selected_index]
"""
#EXTM3U
#EXTVLCOPT:start-time=sec
./videopath
#EXTVLCOPT:start-time=sec
./videopath
"""
with open("/tmp/coconuts.m3u8", "w") as f:
f.write("#EXTM3U\n")
for c in rotated_coconuts:
encoded_path = urllib.parse.quote(c["path"])
sec = c["sec"]
f.write(f"#EXTVLCOPT:start-time={sec}\n")
f.write(f"{encoded_path}\n")
cmd = ["vlc", "--no-video-title-show", "--loop", "/tmp/coconuts.m3u8"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)