Created
August 12, 2024 03:36
-
-
Save dclamage/ffed6464ebe878148229975d73c91062 to your computer and use it in GitHub Desktop.
Converts EDL to YouTube timestamps
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 os | |
def edl_to_youtube_chapters(edl_filepath): | |
youtube_chapters = [] | |
with open(edl_filepath, 'r') as edl_file: | |
for line in edl_file: | |
if line.strip() and line[0].isdigit(): | |
time_start = line.split()[4] | |
hours, minutes, seconds = time_start.split(':')[0:3] | |
if hours == '00': | |
time_start_formatted = f"{minutes}:{seconds}" # MM:SS format | |
else: | |
time_start_formatted = f"{hours}:{minutes}:{seconds}" # HH:MM:SS format | |
next_line = next(edl_file) | |
title = next_line.split('|M:')[1].split(' |')[0] | |
youtube_chapters.append(f"{time_start_formatted} {title}") | |
return youtube_chapters | |
def write_chapters_to_file(chapters, output_filepath): | |
with open(output_filepath, 'w') as output_file: | |
for chapter in chapters: | |
output_file.write(chapter + "\n") | |
def convert_all_edl_files_in_directory(directory): | |
for filename in os.listdir(directory): | |
if filename.endswith(".edl"): | |
chapters = edl_to_youtube_chapters(filename) | |
output_filepath = os.path.splitext(filename)[0] + ".txt" # replace .edl extension with .txt | |
write_chapters_to_file(chapters, output_filepath) | |
# Usage | |
convert_all_edl_files_in_directory('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment