diff --git a/.pep8 b/.pep8 new file mode 100644 index 0000000..a2d556f --- /dev/null +++ b/.pep8 @@ -0,0 +1,2 @@ +[pycodestyle] +max_line_length = 99 diff --git a/easing.py b/easing.py index c362019..a7deb10 100644 --- a/easing.py +++ b/easing.py @@ -4,208 +4,233 @@ import math + def easeLinear(t, b, c, d): - return c*t/d + b + return c*t/d + b def easeOutCubic(t, b, c, d): - t=float(t)/d-1 - return c*((t)*t*t + 1) + b + t = float(t)/d-1 + return c*((t)*t*t + 1) + b + def easeInCubic(t, b, c, d): - t=float(t)/d - return c*(t)*t*t + b; + t = float(t)/d + return c*(t)*t*t + b def easeInQuad(t, b, c, d): - t /= d - return c*t*t + b + t /= d + return c*t*t + b + def easeOutQuad(t, b, c, d): - t /= d - return -c * t*(t-2) + b + t /= d + return -c * t*(t-2) + b + def easeInOutQuad(t, b, c, d): - t /= d/2 - if t < 1: - return c/2*t*t + b - t-=1 - return -c/2 * (t*(t-2) - 1) + b + t /= d/2 + if t < 1: + return c/2*t*t + b + t -= 1 + return -c/2 * (t*(t-2) - 1) + b def easeInOutCubic(t, b, c, d): - t /= d/2 - if t < 1: - return c/2*t*t*t + b - t -= 2 - return c/2*(t*t*t + 2) + b + t /= d/2 + if t < 1: + return c/2*t*t*t + b + t -= 2 + return c/2*(t*t*t + 2) + b + def easeInQuart(t, b, c, d): - t /= d - return c*t*t*t*t + b + t /= d + return c*t*t*t*t + b + def easeOutQuart(t, b, c, d): - t /= d - t -= 1 - return -c * (t*t*t*t - 1) + b + t /= d + t -= 1 + return -c * (t*t*t*t - 1) + b + def easeInOutQuart(t, b, c, d): - t /= d/2 - if t < 1: - return c/2*t*t*t*t + b - t -= 2 - return -c/2 * (t*t*t*t - 2) + b + t /= d/2 + if t < 1: + return c/2*t*t*t*t + b + t -= 2 + return -c/2 * (t*t*t*t - 2) + b + def easeInQuint(t, b, c, d): - t /= d - return c*t*t*t*t*t + b + t /= d + return c*t*t*t*t*t + b + def easeOutQuint(t, b, c, d): - t /= d - t -= 1 - return c*(t*t*t*t*t + 1) + b + t /= d + t -= 1 + return c*(t*t*t*t*t + 1) + b + def easeInOutQuint(t, b, c, d): - t /= d/2 - if t < 1: - return c/2*t*t*t*t*t + b - t -= 2 - return c/2*(t*t*t*t*t + 2) + b + t /= d/2 + if t < 1: + return c/2*t*t*t*t*t + b + t -= 2 + return c/2*(t*t*t*t*t + 2) + b + def easeInSine(t, b, c, d): - return -c * math.cos(t/d * (math.pi/2)) + c + b + return -c * math.cos(t/d * (math.pi/2)) + c + b + def easeOutSine(t, b, c, d): - return c * math.sin(t/d * (math.pi/2)) + b + return c * math.sin(t/d * (math.pi/2)) + b def easeInOutSine(t, b, c, d): - return -c/2 * (math.cos(math.pi*t/d) - 1) + b + return -c/2 * (math.cos(math.pi*t/d) - 1) + b + def easeInExpo(t, b, c, d): - return c * math.pow( 2, 10 * (t/d - 1) ) + b + return c * math.pow(2, 10 * (t/d - 1)) + b + def easeOutExpo(t, b, c, d): - return c * ( -math.pow( 2, -10 * t/d ) + 1 ) + b + return c * (-math.pow(2, -10 * t/d) + 1) + b def easeInOutExpo(t, b, c, d): - t /= d/2 - if t < 1: - return c/2 * math.pow( 2, 10 * (t - 1) ) + b - t -= 1 - return c/2 * ( -math.pow( 2, -10 * t) + 2 ) + b + t /= d/2 + if t < 1: + return c/2 * math.pow(2, 10 * (t - 1)) + b + t -= 1 + return c/2 * (-math.pow(2, -10 * t) + 2) + b + def easeInCirc(t, b, c, d): - t /= d - return -c * (math.sqrt(1 - t*t) - 1) + b + t /= d + return -c * (math.sqrt(1 - t*t) - 1) + b + def easeOutCirc(t, b, c, d): - t /= d; - t -= 1 - return c * math.sqrt(1 - t*t) + b + t /= d + t -= 1 + return c * math.sqrt(1 - t*t) + b + def easeInOutCirc(t, b, c, d): - t /= d/2 - if t < 1: - return -c/2 * (math.sqrt(1 - t*t) - 1) + b - t -= 2 - return c/2 * (math.sqrt(1 - t*t) + 1) + b + t /= d/2 + if t < 1: + return -c/2 * (math.sqrt(1 - t*t) - 1) + b + t -= 2 + return c/2 * (math.sqrt(1 - t*t) + 1) + b -def easeInElastic(t, b, c, d, s = 1.70158): - a = c +def easeInElastic(t, b, c, d, s=1.70158): + a = c - if t == 0: - return b - t /= d - if t == 1: - return b + c + if t == 0: + return b + t /= d + if t == 1: + return b + c - p = d * 0.3 - if a < abs(c): - a = c - s = p / 4 - else: - s = p / (2 * math.pi) * math.asin(c / a) + p = d * 0.3 + if a < abs(c): + a = c + s = p / 4 + else: + s = p / (2 * math.pi) * math.asin(c / a) - t -= 1 - return -(a * pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b + t -= 1 + return -(a * pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b -def easeOutElastic(t, b, c, d, a = 1.70158): - if t == 0: - return b - t /= d - if t == 1: - return b + c - p = d * 0.3 - if a < abs(c): - a, s = c, p / 4 - else: - s = p / (2 * math.pi) * math.asin(c / a) +def easeOutElastic(t, b, c, d, a=1.70158): + if t == 0: + return b + t /= d + if t == 1: + return b + c - return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b + p = d * 0.3 + if a < abs(c): + a, s = c, p / 4 + else: + s = p / (2 * math.pi) * math.asin(c / a) -def easeInOutElastic(t, b, c, d, a = 1.70158): - if t == 0: - return b - t /= (d / 2) - if t == 2: - return b + c + return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b - p = d * (0.3 * 1.5) - if a < abs(c): - a, s = c, p / 4 - else: - s = p / (2 * math.pi) * math.asin(c / a) - if t < 1: - t -= 1 - return -0.5 * (a * pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b +def easeInOutElastic(t, b, c, d, a=1.70158): + if t == 0: + return b + t /= (d / 2) + if t == 2: + return b + c - t -= 1 - return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p ) * 0.5 + c + b + p = d * (0.3 * 1.5) + if a < abs(c): + a, s = c, p / 4 + else: + s = p / (2 * math.pi) * math.asin(c / a) -def easeInBack(t, b, c, d, s = 1.70158): - t /= d - return c * t * t * ((s + 1) * t - s) + b + if t < 1: + t -= 1 + return -0.5 * (a * pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b -def easeOutBack(t, b, c, d, s = 1.70158): - t = t / d - 1 - return c * (t * t * ((s + 1) * t + s) + 1) + b + t -= 1 + return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) * 0.5 + c + b -def easeInOutBack(t, b, c, d, s = 1.70158): - t /= d / 2 - s *= 1.525 - if t < 1: - return c / 2 * (t * t * ((s + 1) * t - s)) + b; - t -= 2 - return c/2 * (t * t * ((s + 1) * t + s) + 2) + b; +def easeInBack(t, b, c, d, s=1.70158): + t /= d + return c * t * t * ((s + 1) * t - s) + b + + +def easeOutBack(t, b, c, d, s=1.70158): + t = t / d - 1 + return c * (t * t * ((s + 1) * t + s) + 1) + b + + +def easeInOutBack(t, b, c, d, s=1.70158): + t /= d / 2 + s *= 1.525 + if t < 1: + return c / 2 * (t * t * ((s + 1) * t - s)) + b + + t -= 2 + return c/2 * (t * t * ((s + 1) * t + s) + 2) + b + def easeInBounce(t, b, c, d): - return c - easeOutBounce(d-t, 0, c, d) + b; + return c - easeOutBounce(d-t, 0, c, d) + b + def easeOutBounce(t, b, c, d): - t /= d - if t < (1/2.75): - return c*(7.5625*t*t) + b; + t /= d + if t < (1/2.75): + return c*(7.5625*t*t) + b - elif t < (2/2.75): - t -= (1.5/2.75) - return c*(7.5625*t*t + 0.75) + b; + elif t < (2/2.75): + t -= (1.5/2.75) + return c*(7.5625*t*t + 0.75) + b - elif t < (2.5/2.75): - t -= (2.25/2.75) - return c*(7.5625*t*t + 0.9375) + b; + elif t < (2.5/2.75): + t -= (2.25/2.75) + return c*(7.5625*t*t + 0.9375) + b + + else: + t -= (2.625/2.75) + return c*(7.5625*t*t + 0.984375) + b - else: - t -= (2.625/2.75) - return c*(7.5625*t*t + 0.984375) + b; def easeInOutBounce(t, b, c, d): - if t < d/2: - return easeInBounce(t*2, 0, c, d) * .5 + b; + if t < d/2: + return easeInBounce(t*2, 0, c, d) * .5 + b - return easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b; + return easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b diff --git a/make-adobe-after-effects.py b/make-adobe-after-effects.py index 8e431e5..fb028ef 100755 --- a/make-adobe-after-effects.py +++ b/make-adobe-after-effects.py @@ -109,7 +109,7 @@ if not args.debug and not args.pause and not args.outro and not args.bgloop and error("Either specify --debug, --pause, --outro or supply a schedule") if args.debug: - #persons = ['blubbel'] + # persons = ['blubbel'] persons = ['Vitor Sakaguti', 'Sara', 'A.L. Fehlhaber'] events = [{ 'id': 11450, @@ -177,15 +177,15 @@ def run_output(command, **kwargs): def run_once(command, **kwargs): - DETACHED_PROCESS = 0x00000008 - return subprocess.Popen( - fmt_command(command, **kwargs), - shell=False, - stdin=None, - stdout=None, - stderr=None, - close_fds=True, - creationflags=DETACHED_PROCESS) + DETACHED_PROCESS = 0x00000008 + return subprocess.Popen( + fmt_command(command, **kwargs), + shell=False, + stdin=None, + stdout=None, + stderr=None, + close_fds=True, + creationflags=DETACHED_PROCESS) def enqueue_job(event): @@ -227,16 +227,16 @@ def enqueue_job(event): with open(script_doc, 'w', encoding='utf-8') as fp: fp.write(scriptstr) - copyfile(args.project+args.introfile,work_doc) + copyfile(args.project+args.introfile, work_doc) if platform.system() == 'Darwin': - copyfile(args.project+'intro.scpt',ascript_doc) + copyfile(args.project+'intro.scpt', ascript_doc) run('osascript {ascript_path} {scriptpath}', - scriptpath=script_doc, - ascript_path=ascript_doc) + scriptpath=script_doc, + ascript_path=ascript_doc) - #run('osascript {ascript_path} {jobpath} {scriptpath}', + # run('osascript {ascript_path} {jobpath} {scriptpath}', # jobpath=work_doc, # scriptpath=script_doc, # ascript_path=ascript_doc) @@ -247,7 +247,7 @@ def enqueue_job(event): if platform.system() == 'Windows': run_once(r'C:/Program\ Files/Adobe/Adobe\ After\ Effects\ 2022/Support\ Files/AfterFX.exe -noui -r {scriptpath}', - scriptpath=script_doc) + scriptpath=script_doc) time.sleep(5) @@ -256,7 +256,7 @@ def enqueue_job(event): locationpath=intermediate_clip) if args.debug or args.keep: path = tempdir.name - dirs = os.listdir( path ) + dirs = os.listdir(path) for file in dirs: print(file) @@ -277,7 +277,7 @@ def finalize_job(job_id, event): if args.alpha: ffprobe = run_output('ffprobe -i {input} -show_streams -select_streams a -loglevel error', - input=intermediate_clip) + input=intermediate_clip) if ffprobe: run('ffmpeg -threads 0 -y -hide_banner -loglevel error -i {input} -c:v qtrle -movflags faststart -aspect 16:9 -c:a mp2 -b:a 384k -shortest -f mov {output}', input=intermediate_clip, @@ -288,7 +288,7 @@ def finalize_job(job_id, event): output=final_clip) else: ffprobe = run_output('ffprobe -i {input} -show_streams -select_streams a -loglevel error', - input=intermediate_clip) + input=intermediate_clip) if ffprobe: event_print(event, "finalize with audio from source file") run('ffmpeg -threads 0 -y -hide_banner -loglevel error -i {input} -c:v mpeg2video -q:v 2 -aspect 16:9 -c:a mp2 -b:a 384k -shortest -f mpegts {output}', diff --git a/make-apple-motion.py b/make-apple-motion.py index 73899d9..1d4c631 100755 --- a/make-apple-motion.py +++ b/make-apple-motion.py @@ -117,6 +117,7 @@ def fmt_command(command, **kwargs): def run(command, **kwargs): os.system(fmt_command(command, **kwargs)) + def run_output(command, **kwargs): # Apple Compressor behaves weirdly with its stdout. It will not terminate right when ran through # os.subprocess, but work fine when run via os.system. To still get the output, we pipe it into a @@ -127,6 +128,7 @@ def run_output(command, **kwargs): os.system(f'{cmd} >{t.name} 2>&1') return t.read().decode('utf-8') + def enqueue_job(event): event_id = str(event['id']) work_doc = os.path.join(tempdir.name, event_id + '.motn') @@ -156,7 +158,8 @@ def enqueue_job(event): def fetch_job_status(): - compressor_status = run_output('/Applications/Compressor.app/Contents/MacOS/Compressor -monitor') + compressor_status = run_output( + '/Applications/Compressor.app/Contents/MacOS/Compressor -monitor') job_status_matches = re.finditer(r"", compressor_status) status_dict = {} @@ -188,7 +191,8 @@ def filter_finished_jobs(active_jobs): elif status == 'Successful': finished_jobs.append((job_id, event)) else: - event_print(event, "failed with staus=" + status + " – removing from postprocessing queue") + event_print(event, "failed with staus=" + status + + " – removing from postprocessing queue") return new_active_jobs, finished_jobs @@ -209,6 +213,7 @@ def finalize_job(job_id, event): event_print(event, "finalized intro to " + final_clip) + active_jobs = [] if args.ids: @@ -219,7 +224,8 @@ if args.exclude_ids: filtered_events = events filtered_events = filter(lambda event: not args.ids or event['id'] in args.ids, filtered_events) -filtered_events = filter(lambda event: not args.exclude_ids or event['id'] not in args.exclude_ids, filtered_events) +filtered_events = filter( + lambda event: not args.exclude_ids or event['id'] not in args.exclude_ids, filtered_events) filtered_events = list(filtered_events) print("enqueuing {} jobs into compressor".format(len(filtered_events))) diff --git a/make-blender.py b/make-blender.py index 80908b8..99035fe 100644 --- a/make-blender.py +++ b/make-blender.py @@ -19,14 +19,14 @@ from shutil import copyfile titlemap = {} -#titlemap = { +# titlemap = { # "205" : { # "title" : "Attacking CPUs with Power Side Channels from Software" # }, # "20" : { # "title" : "New title for Talk id 20" # } -#} +# } # Parse arguments parser = argparse.ArgumentParser( @@ -117,7 +117,7 @@ if not args.debug and not args.pause and not args.outro and not args.bgloop and error("Either specify --debug, --pause, --outro or supply a schedule") if args.debug: - #persons = ['blubbel'] + # persons = ['blubbel'] persons = ['Vitor Sakaguti', 'Sara', 'A.L. Fehlhaber'] events = [{ 'id': 11450, @@ -228,7 +228,8 @@ def enqueue_job(event): if platform.system() == 'Darwin': if args.debug: - print("running: Blender.app --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip)) + print("running: Blender.app --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % + (work_source, work_doc, intermediate_clip)) run(r'/Applications/Blender.app/Contents/MacOS/Blender --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim', source=work_source, jobpath=work_doc, @@ -236,14 +237,16 @@ def enqueue_job(event): if platform.system() == 'Windows': if args.debug: - print("running: blender.exe --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip)) + print("running: blender.exe --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % + (work_source, work_doc, intermediate_clip)) run(r'C:/Program\ Files/Blender\ Foundation/Blender\ 2.92/blender.exe --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim', source=work_source, jobpath=work_doc, locationpath=intermediate_clip) if platform.system() == 'Linux': if args.debug: - print("running: blender --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip)) + print("running: blender --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % + (work_source, work_doc, intermediate_clip)) run(r'blender --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim', source=work_source, jobpath=work_doc, @@ -261,7 +264,7 @@ def finalize_job(job_id, event): if args.alpha: ffprobe = run_output('ffprobe -i {input} -show_streams -select_streams a -loglevel error', - input=intermediate_clip) + input=intermediate_clip) if ffprobe: run('ffmpeg -threads 0 -y -hide_banner -loglevel error -i {input} -c:v qtrle -movflags faststart -aspect 16:9 -c:a mp2 -b:a 384k -shortest -f mov {output}', input=intermediate_clip, @@ -272,7 +275,7 @@ def finalize_job(job_id, event): output=final_clip) else: ffprobe = run_output('ffprobe -i {input} -show_streams -select_streams a -loglevel error', - input=intermediate_clip) + input=intermediate_clip) if ffprobe: event_print(event, "finalize with audio from source file") run('ffmpeg -threads 0 -y -hide_banner -loglevel error -i {input} -c:v mpeg2video -q:v 2 -aspect 16:9 -c:a mp2 -b:a 384k -shortest -f mpegts {output}', diff --git a/make-ffmpeg-fade.py b/make-ffmpeg-fade.py index 0fc8233..f4e88a3 100755 --- a/make-ffmpeg-fade.py +++ b/make-ffmpeg-fade.py @@ -52,20 +52,21 @@ parser.add_argument('--force', action="store_true", default=False, help=''' args = parser.parse_args() if (args.skip is None): - args.skip = [] + args.skip = [] def headline(str): - print("##################################################") - print(str) - print("##################################################") - print() + print("##################################################") + print(str) + print("##################################################") + print() def error(str): - headline(str) - parser.print_help() - sys.exit(1) + headline(str) + parser.print_help() + sys.exit(1) + cparser = ConfigParser() cparser.read(os.path.join(os.path.dirname(args.project), 'config.ini')) @@ -145,6 +146,7 @@ if args.debug: else: events = list(schedulelib.events(schedule)) + def describe_event(event): return "#{}: {}".format(event['id'], event['title']) @@ -231,58 +233,62 @@ def enqueue_job(event): outfile = os.path.join(os.path.dirname(args.project), event_id + '.ts') videofilter = "drawtext=fontfile={fontfile}:fontsize={fontsize}:fontcolor={fontcolor}:x={x}:y={y}:text='{text}':".format( - fontfile = font_t, - fontsize = title_fontsize, - fontcolor = title_fontcolor, - x = title_x, - y = title_y, - text = t) + fontfile=font_t, + fontsize=title_fontsize, + fontcolor=title_fontcolor, + x=title_x, + y=title_y, + text=t) videofilter += "alpha='if(lt(t,{fade_in_start_time}),0,if(lt(t,{fade_in_end_time}),(t-{fade_in_start_time})/{fade_duration},if(lt(t,{fade_out_start_time}),1,if(lt(t,{fade_out_end_time}),({fade_duration}-(t-{fade_out_start_time}))/{fade_duration},0))))',".format( - fade_in_start_time = title_in, - fade_in_end_time = title_in + fade_duration, - fade_out_start_time = title_in + fade_duration + title_duration, - fade_out_end_time = title_in + fade_duration + title_duration + fade_duration, - fade_duration = fade_duration - ) + fade_in_start_time=title_in, + fade_in_end_time=title_in + fade_duration, + fade_out_start_time=title_in + fade_duration + title_duration, + fade_out_end_time=title_in + fade_duration + title_duration + fade_duration, + fade_duration=fade_duration + ) videofilter += "drawtext=fontfile={fontfile}:fontsize={fontsize}:fontcolor={fontcolor}:x={x}:y={y}:text='{text}':".format( - fontfile = font_s, - fontsize = speaker_fontsize, - fontcolor = speaker_fontcolor, - x = speaker_x, - y = speaker_y, - text = s) + fontfile=font_s, + fontsize=speaker_fontsize, + fontcolor=speaker_fontcolor, + x=speaker_x, + y=speaker_y, + text=s) videofilter += "alpha='if(lt(t,{fade_in_start_time}),0,if(lt(t,{fade_in_end_time}),(t-{fade_in_start_time})/{fade_duration},if(lt(t,{fade_out_start_time}),1,if(lt(t,{fade_out_end_time}),({fade_duration}-(t-{fade_out_start_time}))/{fade_duration},0))))',".format( - fade_in_start_time = speaker_in, - fade_in_end_time = speaker_in + fade_duration, - fade_out_start_time = speaker_in + fade_duration + speaker_duration, - fade_out_end_time = speaker_in + fade_duration + speaker_duration + fade_duration, - fade_duration = fade_duration - ) + fade_in_start_time=speaker_in, + fade_in_end_time=speaker_in + fade_duration, + fade_out_start_time=speaker_in + fade_duration + speaker_duration, + fade_out_end_time=speaker_in + fade_duration + speaker_duration + fade_duration, + fade_duration=fade_duration + ) videofilter += "drawtext=fontfile={fontfile}:fontsize={fontsize}:fontcolor={fontcolor}:x={x}:y={y}:text={text}:".format( - fontfile = font_tt, - fontsize = text_fontsize, - fontcolor = text_fontcolor, - x = text_x, - y = text_y, - text = text_text) + fontfile=font_tt, + fontsize=text_fontsize, + fontcolor=text_fontcolor, + x=text_x, + y=text_y, + text=text_text) videofilter += "alpha='if(lt(t,{fade_in_start_time}),0,if(lt(t,{fade_in_end_time}),(t-{fade_in_start_time})/{fade_duration},if(lt(t,{fade_out_start_time}),1,if(lt(t,{fade_out_end_time}),({fade_duration}-(t-{fade_out_start_time}))/{fade_duration},0))))'".format( - fade_in_start_time = text_in, - fade_in_end_time = text_in + fade_duration, - fade_out_start_time = text_in + fade_duration + text_duration, - fade_out_end_time = text_in + fade_duration + text_duration + fade_duration, - fade_duration = fade_duration - ) + fade_in_start_time=text_in, + fade_in_end_time=text_in + fade_duration, + fade_out_start_time=text_in + fade_duration + text_duration, + fade_out_end_time=text_in + fade_duration + text_duration + fade_duration, + fade_duration=fade_duration + ) if fileformat == '.mov': if alpha == 'true': if prores == 'true': - cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile) + cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format( + infile, videofilter, outfile) else: - cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile) + cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format( + infile, videofilter, outfile) else: - cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile) + cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format( + infile, videofilter, outfile) else: - cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -pix_fmt:v yuv420p -qscale:v 2 -qmin:v 2 -qmax:v 7 -keyint_min 0 -bf 0 -g 0 -maxrate:0 90M -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile) + cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -pix_fmt:v yuv420p -qscale:v 2 -qmin:v 2 -qmax:v 7 -keyint_min 0 -bf 0 -g 0 -maxrate:0 90M -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format( + infile, videofilter, outfile) if args.debug: print(cmd) @@ -321,5 +327,3 @@ for event in events: print('all done') - - diff --git a/make-ffmpeg.py b/make-ffmpeg.py index 9fb7bc1..b43fcc4 100755 --- a/make-ffmpeg.py +++ b/make-ffmpeg.py @@ -55,28 +55,29 @@ parser.add_argument('--force', action="store_true", default=False, help=''' args = parser.parse_args() if (args.skip is None): - args.skip = [] + args.skip = [] def headline(str): - print("##################################################") - print(str) - print("##################################################") - print() + print("##################################################") + print(str) + print("##################################################") + print() def error(str): - headline(str) - parser.print_help() - sys.exit(1) + headline(str) + parser.print_help() + sys.exit(1) + cparser = ConfigParser() cparser.read(os.path.join(os.path.dirname(args.project), 'config.ini')) template = cparser['default']['template'] alpha = cparser['default']['alpha'] prores = cparser['default']['prores'] -fontfile = cparser['default']['fontfile'] # use a font file instead of a font family -inout = cparser['default']['inout'] # in and out time format: t for seconds, n for frame number +fontfile = cparser['default']['fontfile'] # use a font file instead of a font family +inout = cparser['default']['inout'] # in and out time format: t for seconds, n for frame number title_in = cparser['title']['in'] title_out = cparser['title']['out'] @@ -148,6 +149,7 @@ if args.debug: else: events = list(schedulelib.events(schedule)) + def describe_event(event): return "#{}: {}".format(event['id'], event['title']) @@ -194,7 +196,7 @@ def fit_text(string: str, frame_width): def fit_title(string: str): global translation_font translation_font = ImageFont.truetype( - font_t, size=80, encoding="unic") + font_t, size=80, encoding="unic") title = fit_text(string, 1080) return title @@ -203,7 +205,7 @@ def fit_title(string: str): def fit_speaker(string: str): global translation_font translation_font = ImageFont.truetype( - font_s, size=50, encoding="unic") + font_s, size=50, encoding="unic") speaker = fit_text(string, 1080) return speaker @@ -225,7 +227,7 @@ def enqueue_job(event): event_personnames = event_personnames.replace('"', '\\"') t = fit_title(event_title) - t = t.replace(':', "\:") # the ffmpeg command needs colons to be escaped + t = t.replace(':', "\:") # the ffmpeg command needs colons to be escaped s = fit_speaker(event_personnames) if args.debug: @@ -240,33 +242,45 @@ def enqueue_job(event): font_s_win = "/".join(font_s.split("\\")) font_tt_win = "/".join(font_tt.split("\\")) else: - ffmpeg_path = 'ffmpeg' + ffmpeg_path = 'ffmpeg' if fontfile == 'true': if platform.system() == 'Windows': - videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, font_t_win, title_fontsize, title_fontcolor, title_x, title_y, t, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, font_s_win, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, font_tt_win, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) + videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format( + title_in, title_out, font_t_win, title_fontsize, title_fontcolor, title_x, title_y, t, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format( + speaker_in, speaker_out, font_s_win, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format( + text_in, text_out, font_tt_win, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) else: - videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, font_t, title_fontsize, title_fontcolor, title_x, title_y, t, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, font_s, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, font_tt, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) + videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format( + title_in, title_out, font_t, title_fontsize, title_fontcolor, title_x, title_y, t, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format( + speaker_in, speaker_out, font_s, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format( + text_in, text_out, font_tt, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) else: - videofilter = "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, title_fontfamily, title_fontsize, title_fontcolor, title_x, title_y, t, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, speaker_fontfamily, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) - videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, text_fontfamily, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) - + videofilter = "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format( + title_in, title_out, title_fontfamily, title_fontsize, title_fontcolor, title_x, title_y, t, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format( + speaker_in, speaker_out, speaker_fontfamily, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout) + videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format( + text_in, text_out, text_fontfamily, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout) if fileformat == '.mov': if alpha == 'true': if prores == 'true': - cmd = '{3} -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile, ffmpeg_path) + cmd = '{3} -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format( + infile, videofilter, outfile, ffmpeg_path) else: - cmd = '{3} -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile, ffmpeg_path) + cmd = '{3} -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format( + infile, videofilter, outfile, ffmpeg_path) else: - cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile, ffmpeg_path) + cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format( + infile, videofilter, outfile, ffmpeg_path) else: - cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile, ffmpeg_path) + cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format( + infile, videofilter, outfile, ffmpeg_path) if args.debug: print(cmd) @@ -305,5 +319,3 @@ for event in events: print('all done') - - diff --git a/make.py b/make.py index 6c0834c..6f5e3f7 100755 --- a/make.py +++ b/make.py @@ -14,7 +14,8 @@ import renderlib import argparse # Parse arguments -parser = argparse.ArgumentParser(description='C3VOC Intro-Outro-Generator', usage="see help with option -h", formatter_class=argparse.RawTextHelpFormatter) +parser = argparse.ArgumentParser(description='C3VOC Intro-Outro-Generator', + usage="see help with option -h", formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('projectpath', action="store", metavar='yourproject/', type=str, help=''' Path to your project is a required argument. Usage: ./make.py yourproject/ @@ -87,7 +88,8 @@ projectpath = args.projectpath try: project = renderlib.loadProject(projectname) except ImportError: - print("you must specify a project-name as first argument, eg. './make.py sotmeu14'. The supplied value '{0}' seems not to be a valid project (there is no '{0}/__init__.py').\n".format(projectname)) + print( + "you must specify a project-name as first argument, eg. './make.py sotmeu14'. The supplied value '{0}' seems not to be a valid project (there is no '{0}/__init__.py').\n".format(projectname)) raise # using --debug skips the threading, the network fetching of the schedule and @@ -98,7 +100,8 @@ renderlib.args = args def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')): - task = renderlib.Rendertask(infile=infile, outfile=outfile, sequence=sequence, parameters=parameters, workdir=workdir) + task = renderlib.Rendertask(infile=infile, outfile=outfile, + sequence=sequence, parameters=parameters, workdir=workdir) return renderlib.rendertask(task) @@ -188,7 +191,8 @@ def worker(): renderlib.rendertask(task) # print that we're finished - tprint('finished {0}, {1} tasks left'.format(task.outfile, max(0, tasks.qsize() - num_worker_threads))) + tprint('finished {0}, {1} tasks left'.format( + task.outfile, max(0, tasks.qsize() - num_worker_threads))) # mark the task as finished tasks.task_done() diff --git a/renderlib.py b/renderlib.py index 37f1dae..c8e5e84 100644 --- a/renderlib.py +++ b/renderlib.py @@ -17,7 +17,8 @@ fps = 25 debug = True args = None -scheduleTree=None +scheduleTree = None + def loadProject(projectname): sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), projectname)) @@ -45,7 +46,7 @@ class Rendertask: self.parameters = parameters self.outfile = outfile self.workdir = workdir - self.sequence = sequence # deprecated, use animated() + self.sequence = sequence # deprecated, use animated() def animated(self, sequence): atask = self @@ -70,6 +71,8 @@ class Rendertask: return None # try to create all folders needed and skip, they already exist + + def ensurePathExists(path): try: os.makedirs(path) @@ -83,6 +86,7 @@ def ensureFilesRemoved(pattern): for f in glob.glob(pattern): os.unlink(f) + def renderFrame(infile, task, outfile): width = 1920 height = 1080 @@ -93,61 +97,67 @@ def renderFrame(infile, task, outfile): converted.save(filename=outfile) elif args.resvg: # invoke inkscape to convert the generated svg-file into a png inside the .frames-directory - cmd = 'resvg --background white --width={1} --height={2} "{4}" "{3}" 2>&1 >/dev/null'.format(task.workdir, width, height, outfile, infile) - errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir) + cmd = 'resvg --background white --width={1} --height={2} "{4}" "{3}" 2>&1 >/dev/null'.format( + task.workdir, width, height, outfile, infile) + errorReturn = subprocess.check_output( + cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir) if errorReturn != '': print("resvg exited with error\n" + errorReturn) # sys.exit(42) else: # invoke inkscape to convert the generated svg-file into a png inside the .frames-directory - cmd = 'inkscape --export-background=white --export-background-opacity=0 --export-width={1} --export-height={2} --export-filename="{3}" "{4}" --pipe 2>&1 >/dev/null'.format(task.workdir, width, height, os.path.abspath(outfile), os.path.abspath(infile)) - errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir) + cmd = 'inkscape --export-background=white --export-background-opacity=0 --export-width={1} --export-height={2} --export-filename="{3}" "{4}" --pipe 2>&1 >/dev/null'.format( + task.workdir, width, height, os.path.abspath(outfile), os.path.abspath(infile)) + errorReturn = subprocess.check_output( + cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir) if errorReturn != '': print("inkscape exited with error\n" + errorReturn) # sys.exit(42) + def cachedRenderFrame(frame, frameNr, task, cache): - skip_rendering = False - # skip first n frames, to speed up rerendering during debugging - if 'only_rerender_frames_after' in task.parameters: - skip_rendering = (frameNr <= task.parameters['only_rerender_frames_after']) + skip_rendering = False + # skip first n frames, to speed up rerendering during debugging + if 'only_rerender_frames_after' in task.parameters: + skip_rendering = (frameNr <= task.parameters['only_rerender_frames_after']) - if args.skip_frames: - skip_rendering = (frameNr <= args.skip_frames) + if args.skip_frames: + skip_rendering = (frameNr <= args.skip_frames) - if args.only_frame: - skip_rendering = (frameNr != args.only_frame) + if args.only_frame: + skip_rendering = (frameNr != args.only_frame) - # print a line for each and every frame generated - if debug and not skip_rendering: - print("frameNr {0:3d} => {1}".format(frameNr, frame)) + # print a line for each and every frame generated + if debug and not skip_rendering: + print("frameNr {0:3d} => {1}".format(frameNr, frame)) - frame = tuple(frame) - if frame in cache: - if debug: - print("cache hit, reusing frame {0}".format(cache[frame])) + frame = tuple(frame) + if frame in cache: + if debug: + print("cache hit, reusing frame {0}".format(cache[frame])) - framedir = task.workdir + "/.frames/" - shutil.copyfile("{0}/{1:04d}.png".format(framedir, cache[frame]), "{0}/{1:04d}.png".format(framedir, frameNr)) + framedir = task.workdir + "/.frames/" + shutil.copyfile("{0}/{1:04d}.png".format(framedir, + cache[frame]), "{0}/{1:04d}.png".format(framedir, frameNr)) - return - elif not skip_rendering: - cache[frame] = frameNr + return + elif not skip_rendering: + cache[frame] = frameNr - svgfile = '{0}/.frames/{1:04d}.svg'.format(task.workdir, frameNr) + svgfile = '{0}/.frames/{1:04d}.svg'.format(task.workdir, frameNr) - if not skip_rendering: - with SVGTemplate(task, svgfile) as svg: - svg.replacetext() - svg.transform(frame) - svg.write() + if not skip_rendering: + with SVGTemplate(task, svgfile) as svg: + svg.replacetext() + svg.transform(frame) + svg.write() - outfile = '{0}/.frames/{1:04d}.png'.format(task.workdir, frameNr) - renderFrame(svgfile, task, outfile) + outfile = '{0}/.frames/{1:04d}.png'.format(task.workdir, frameNr) + renderFrame(svgfile, task, outfile) - # increment frame-number - frameNr += 1 + # increment frame-number + frameNr += 1 def rendertask_image(task): @@ -157,6 +167,7 @@ def rendertask_image(task): svg.write() renderFrame(svgfile, task, task.outfile) + def rendertask_video(task): # iterate through the animation sequence frame by frame # frame is a ... tbd @@ -171,7 +182,8 @@ def rendertask_video(task): ensureFilesRemoved(os.path.join(task.workdir, task.outfile)) if task.outfile.endswith('.png'): - cmd = 'cd {0} && cp ".frames/{1:04d}.png" "{2}"'.format(task.workdir, args.only_frame, task.outfile) + cmd = 'cd {0} && cp ".frames/{1:04d}.png" "{2}"'.format( + task.workdir, args.only_frame, task.outfile) # invoke avconv aka ffmpeg and renerate a lossles-dv from the frames # if we're not in debug-mode, suppress all output @@ -192,11 +204,14 @@ def rendertask_video(task): cmd += '-shortest -f mpegts "{0}"'.format(task.outfile) elif task.outfile.endswith('.mov'): cmd = 'cd {0} && '.format(task.workdir) - cmd += 'ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -f image2 -i .frames/%04d.png -r 25 -shortest -c:v qtrle -f mov "{0}"'.format(task.outfile) + cmd += 'ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -f image2 -i .frames/%04d.png -r 25 -shortest -c:v qtrle -f mov "{0}"'.format( + task.outfile) elif task.outfile.endswith('.mkv'): - cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -aspect 16:9 -c copy -shortest "{1}"'.format(task.workdir, task.outfile) + cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -aspect 16:9 -c copy -shortest "{1}"'.format( + task.workdir, task.outfile) else: - cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -target pal-dv -aspect 16:9 -shortest "{1}"'.format(task.workdir, task.outfile) + cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -target pal-dv -aspect 16:9 -shortest "{1}"'.format( + task.workdir, task.outfile) if debug: print(cmd) @@ -208,15 +223,16 @@ def rendertask_video(task): if r != 0: sys.exit() + def rendertask(task): global args # in debug mode we have no thread-worker which prints its progress if debug: print("generating {0} from {1}".format(task.outfile, task.infile)) - ## Hacky workaround: Fix this properly without breaking the - ## support for partially rendered intros - if True: #args.skip_frames and 'only_rerender_frames_after' not in task.parameters: + # Hacky workaround: Fix this properly without breaking the + # support for partially rendered intros + if True: # args.skip_frames and 'only_rerender_frames_after' not in task.parameters: if os.path.isdir(os.path.join(task.workdir, '.frames')): print("Removing", os.path.join(task.workdir, '.frames')) shutil.rmtree(os.path.join(task.workdir, '.frames')) @@ -241,4 +257,3 @@ try: except ImportError: def colored(str, col): return str - diff --git a/schedulelib.py b/schedulelib.py index 3fabdf4..340e4d8 100644 --- a/schedulelib.py +++ b/schedulelib.py @@ -4,7 +4,7 @@ import re from lxml import etree from urllib.request import urlopen -scheduleTree=None +scheduleTree = None # Download the Events-Schedule and parse all Events out of it. Yield a tupel for each Event @@ -21,10 +21,11 @@ def downloadSchedule(scheduleUrl): parser = etree.XMLParser(huge_tree=True) return etree.fromstring(xml, parser) + def getSchedule(scheduleUrl): global scheduleTree if not scheduleTree: - scheduleTree=downloadSchedule(scheduleUrl) + scheduleTree = downloadSchedule(scheduleUrl) return scheduleTree @@ -62,6 +63,7 @@ def persons(scheduleUrl, personmap={}, taglinemap={}, forEventId=None): 'tagline': tagline } + def events(scheduleUrl, titlemap={}): schedule = getSchedule(scheduleUrl) # iterate all days @@ -108,7 +110,7 @@ def events(scheduleUrl, titlemap={}): 'personnames': ', '.join(personnames), 'room': room.attrib['name'], 'track': event.find('track').text, - 'url': url + 'url': url } @@ -117,4 +119,3 @@ try: except ImportError: def colored(str, col): return str - diff --git a/script-Z-preroll-generator.py b/script-Z-preroll-generator.py index e95f1ef..573ea6e 100755 --- a/script-Z-preroll-generator.py +++ b/script-Z-preroll-generator.py @@ -10,17 +10,17 @@ import renderlib import c3t_rpc_client as rpc try: - from termcolor import colored + from termcolor import colored except ImportError: - def colored(str, col): - return str + def colored(str, col): + return str print("C3TT preroll generator") renderlib.debug = True if os.environ.get('CRS_TOKEN') is None or os.environ.get('CRS_SECRET') is None: - print('CRS_TOKEN or CRS_SECRET is empty. did you source the tracker-scripts-profile?') - sys.exit(1) + print('CRS_TOKEN or CRS_SECRET is empty. did you source the tracker-scripts-profile?') + sys.exit(1) ticket_type = 'recording' ticket_state = 'generating' @@ -32,45 +32,48 @@ secret = os.environ['CRS_SECRET'] filter = {} if not os.environ.get('CRS_ROOM') is None: - filter['Fahrplan.Room'] = os.environ['CRS_ROOM'] + filter['Fahrplan.Room'] = os.environ['CRS_ROOM'] projects = {} + + def generatePreroll(ticket): - print(ticket) - projectname = ticket.get('Processing.Prerolls.Slug', ticket['Meta.Acronym']) - if not projectname in projects: - projects[projectname] = renderlib.loadProject(projectname) + print(ticket) + projectname = ticket.get('Processing.Prerolls.Slug', ticket['Meta.Acronym']) + if not projectname in projects: + projects[projectname] = renderlib.loadProject(projectname) - project = projects[projectname] - task = project.ticket(ticket) - task.outfile = os.path.join(ticket['Processing.Path.Intros'], ticket['Fahrplan.ID'] + '.dv') - task.workdir = os.path.join(os.getcwd(), projectname, 'artwork') + project = projects[projectname] + task = project.ticket(ticket) + task.outfile = os.path.join(ticket['Processing.Path.Intros'], ticket['Fahrplan.ID'] + '.dv') + task.workdir = os.path.join(os.getcwd(), projectname, 'artwork') - print(colored("rendering", 'green')) - renderlib.rendertask(task) + print(colored("rendering", 'green')) + renderlib.rendertask(task) - if hasattr(project, 'deploy'): - print(colored("deploying", 'green')) - project.deploy(ticket, task) + if hasattr(project, 'deploy'): + print(colored("deploying", 'green')) + project.deploy(ticket, task) while True: - print(colored('Asking RPC for {0}-tickets which are ready for state {1}'.format(ticket_type, ticket_state), 'yellow')) + print(colored( + 'Asking RPC for {0}-tickets which are ready for state {1}'.format(ticket_type, ticket_state), 'yellow')) - ticket_id = rpc.assignNextUnassignedForState(ticket_type, ticket_state, url, token, host, secret, filter) - if ticket_id != False: - ticket = rpc.getTicketProperties(str(ticket_id), url, token, host, secret) - try: - generatePreroll(ticket) - rpc.setTicketDone(str(ticket_id), url, token, host, secret) - except: - error = str(traceback.format_exc()) - print(colored(error, 'red')) - rpc.setTicketFailed(str(ticket_id), error, url, token, host, secret) - - else: - print('No ticket found') - - print('Sleeping for 30 seconds') - time.sleep(30); + ticket_id = rpc.assignNextUnassignedForState( + ticket_type, ticket_state, url, token, host, secret, filter) + if ticket_id != False: + ticket = rpc.getTicketProperties(str(ticket_id), url, token, host, secret) + try: + generatePreroll(ticket) + rpc.setTicketDone(str(ticket_id), url, token, host, secret) + except: + error = str(traceback.format_exc()) + print(colored(error, 'red')) + rpc.setTicketFailed(str(ticket_id), error, url, token, host, secret) + else: + print('No ticket found') + + print('Sleeping for 30 seconds') + time.sleep(30) diff --git a/svgtemplate.py b/svgtemplate.py index 4391214..00050e1 100644 --- a/svgtemplate.py +++ b/svgtemplate.py @@ -11,6 +11,7 @@ from xml.sax.saxutils import escape as xmlescape cssutils.ser.prefs.lineSeparator = ' ' cssutils.log.setLevel(logging.FATAL) + class SVGTemplate: def __init__(self, task, outfile): self.task = task