Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: added title/desc checks to split.py #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tools/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ def make_thumbnail(video, time, outfile):

return ret == 0

def validate_youtube_title(title):
# https://developers.google.com/youtube/terms/required-minimum-functionality#data-requirements
if len(title) > 100:
raise Exception(f"Title '{title}' is longer than 100 characters. Modify JSON to include a valid youtube_title field.")
if "<" in title or ">" in title:
raise Exception(f"Title '{title}' contains an invalid character. Modify JSON to include a valid youtube_title field.")

def validate_youtube_description(desc):
# https://developers.google.com/youtube/terms/required-minimum-functionality#data-requirements
if len(desc.encode('utf-8')) > 5000:
raise Exception(f"Description '{desc}' is longer than 5000 bytes. Modify JSON to include a valid youtube_description field.")
if "<" in desc or ">" in desc:
raise Exception(f"Description '{desc}' contains an invalid character. Modify JSON to include a valid youtube_description field.")

def make_video_description(talk, desc):
link = "https://www.socallinuxexpo.org" + talk["path"]
return f"""\
Talk by {talk["speakers"]}

{link}

{desc}"""

def parse_args():
parser = argparse.ArgumentParser(description="""\
Takes a JSON file generated by the scale-av-cutter, downloads each full day
Expand Down Expand Up @@ -134,6 +157,11 @@ def main():
talk_path = os.path.join(subdir_path, talk_name)
thumbnail_path = os.path.join(subdir_path, image_name)

youtube_desc = make_video_description(talk, talk["description"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be done further up all at once prior to downloading / cutting any video. With potentially long-processing scripts, as much validation should be done upfront as possible, instead of potentially having the user come back from dinner to see that it threw an exception after processing one video.

I'm not sure if it'll be used, but this also makes it cleaner to offer a cmdline arg to not do this validation, say if the user really doesn't care about fixing descriptions right now. Letting the validation in upload.py stay is fine.

youtube_title = talk.get("youtube_title", talk["title"])
validate_youtube_title(youtube_title)
validate_youtube_description(youtube_desc)

if not make_cut(video_path, start, end, outfile=talk_path):
if args.skip_download_failure:
print(f"WARNING: Failed to cut clip of {title}. Skipping.")
Expand Down