Created
October 24, 2021 17:44
-
-
Save rougeth/f9726e446f39c56687cf8d74e5e914fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import toml | |
from slugify import slugify | |
def load_config_file(): | |
try: | |
path = sys.argv[1] | |
except IndexError: | |
raise Exception("TOML config path required") | |
return toml.load(path) | |
def get_opening_path(): | |
try: | |
return sys.argv[2] | |
except IndexError: | |
raise Exception("Opening file path required") | |
def slots_with_streaming_defined(config): | |
slots = config["slot"] | |
slots = filter(lambda s: s.get("stream"), slots) | |
slots = filter(lambda s: not s.get("youtube_link"), slots) | |
return slots | |
def get_output_filename(slot): | |
date = slot["start_at"].strftime("%Y-%m-%d") | |
room = slot.get("room") or slot["type"] | |
room = slugify(room) | |
author = slot.get("author") or slot["name"] | |
author = slugify(author) | |
return f"{date}-{room}-{author}.mp4" | |
def youtube_title_talk(slot): | |
prefix = "[PyBR2021]" | |
title = slot["name"].strip() | |
author = slot["author"].strip() | |
return f"{prefix} {title} - {author}" | |
def youtube_upload_command(slot): | |
prefix = "youtube-upload" | |
kwargs = { | |
"title": youtube_title_talk(slot), | |
"playlist": "Python Brasil 2021 (EDITADO)", | |
"privacy": "unlisted", | |
} | |
arguments = " ".join([ | |
f'--{arg}="{value}"' for arg, value in kwargs.items() | |
]) | |
output = get_output_filename(slot) | |
return f"{prefix} {arguments} output/{output}" | |
def cut_and_concat_command(slot, opening_path): | |
source = slot["stream"]["filename"] | |
output = get_output_filename(slot) | |
start_at = slot["stream"]["start_at"] | |
end_at = slot["stream"]["end_at"] | |
duration = end_at - start_at | |
return f'cut_and_concat "videos/{source}" output/{output} {opening_path} {start_at} {duration}' | |
def main(): | |
config = load_config_file() | |
opening_path = get_opening_path() | |
slots = slots_with_streaming_defined(config) | |
slots = sorted(slots, key=lambda i: i.get("room")) | |
for slot in slots: | |
prefix = f"{slot['start_at'].date()} {slugify(slot['room'])} - " | |
if slot["type"] == "talk": | |
title = youtube_title_talk(slot) | |
alert = "!!!" if len(title) > 100 else "" | |
print(prefix + alert + title) | |
print(prefix + cut_and_concat_command(slot, opening_path)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment