to infinity
This commit is contained in:
parent
582bcf1813
commit
6e4e8ca7a6
4 changed files with 146 additions and 10 deletions
66
render.py
66
render.py
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
from collections import defaultdict
|
||||
from glob import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
|
@ -609,3 +610,68 @@ def update_subtitles(options):
|
|||
srt = ox.srt.encode(subs)
|
||||
write_if_new(str(path), srt, 'b')
|
||||
|
||||
|
||||
def update_m3u(render_prefix, exclude=[]):
|
||||
files = ox.sorted_strings(glob(render_prefix + "*/*/back.mp4"))
|
||||
for ex in exclude:
|
||||
files = [f for f in files if not f.startswith(ex + "/")]
|
||||
back_m3u = "\n".join(files)
|
||||
back_m3u = back_m3u.replace(render_prefix, "")
|
||||
front_m3u = back_m3u.replace("back.mp4", "front.mp4")
|
||||
|
||||
back_m3u_f = render_prefix + "back.m3u"
|
||||
front_m3u_f = render_prefix + "front.m3u"
|
||||
|
||||
with open(back_m3u_f + "_", "w") as fd:
|
||||
fd.write(back_m3u)
|
||||
with open(front_m3u_f + "_", "w") as fd:
|
||||
fd.write(front_m3u)
|
||||
shutil.move(front_m3u_f + "_", front_m3u_f)
|
||||
cmd = ["scp", front_m3u_f, "front:" + front_m3u_f]
|
||||
subprocess.check_call(cmd)
|
||||
shutil.move(back_m3u_f + "_", back_m3u_f)
|
||||
|
||||
|
||||
def render_infinity(options):
|
||||
prefix = options['prefix']
|
||||
duration = int(options['duration'])
|
||||
base = int(options['offset'])
|
||||
|
||||
state_f = os.path.join(prefix, "infinity.json")
|
||||
if os.path.exists(state_f):
|
||||
with open(state_f) as fd:
|
||||
state = json.load(fd)
|
||||
else:
|
||||
state = {
|
||||
"offset": 100,
|
||||
"max-items": 30
|
||||
}
|
||||
for key in ("prefix", "duration"):
|
||||
state[key] = options[key]
|
||||
|
||||
while True:
|
||||
render_prefix = state["prefix"] + "/render/"
|
||||
current = [
|
||||
f for f in os.listdir(render_prefix)
|
||||
if f.isdigit() and os.path.isdir(render_prefix + f)
|
||||
]
|
||||
if len(current) > state["max-items"]:
|
||||
current = ox.sorted_strings(current)
|
||||
remove = current[-state["max-items"]:]
|
||||
update_m3u(render_prefix, exclude=remove)
|
||||
for folder in remove:
|
||||
folder = render_prefix + folder
|
||||
print("remove", folder)
|
||||
#shutil.rmtree(folder)
|
||||
cmd = ["ssh", "front", "rm", "-r", folder]
|
||||
print(cmd)
|
||||
#subprocess.check_call(cmd)
|
||||
render_all(state)
|
||||
path = "%s%s/" % (render_prefix, state["offset"])
|
||||
cmd = ['rsync', '-a', path, "front:" + path]
|
||||
subprocess.check_call(cmd)
|
||||
update_m3u(render_prefix)
|
||||
state["offset"] += 1
|
||||
with open(state_f + "~", "w") as fd:
|
||||
json.dump(state, fd, indent=2)
|
||||
shutil.move(state_f + "~", state_f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue