Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import sys
import toml
from slugify import slugify
def load_config_file():
path = sys.argv[1]
except IndexError:
raise Exception("TOML config path required")
return toml.load(path)
def get_opening_path():
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__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment