diff --git a/tools/split.py b/tools/split.py index 330b69b..4e14f9c 100755 --- a/tools/split.py +++ b/tools/split.py @@ -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 @@ -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"]) + 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.")