EDL Extension Cleaner

I needed to remove the extensions from the filenames in an edl today, so I wrote this right quick. I’m sure some of you out there will need it too or at the very least a template to do something more complicated. It’s written for Python 2.6 and up.

import os
import sys
import re
import string

###v3 changed to work only on lines that start with 00
import re

def process_text(input_filename, output_filename):
    """Removes extra characters from filenames in the input file and writes the processed text to the output file."""
    with open(input_filename, 'r') as input_file:  # Open input file separately
        with open(output_filename, 'w') as output_file:  # Open output file separately
            for line in input_file:
                if line.startswith("00"):
                    filename = line.split()[1]
                    #print(filename)
                    short_filename = filename.split('.')[0]
                    print(short_filename)
                    line = line.replace(filename, short_filename)
                output_file.write(line)

if __name__ == "__main__":
    input_filename = sys.argv[1]  # grabs file from cmd line
    output_filename = input_filename.split('.')[0] + "_cleaned.edl"  # Use string concatenation for Python 2.6
    process_text(input_filename, output_filename)
    print("File processed successfully! Output saved to: %s" % output_filename)  # Use %-formatting for Python 2.6



Happy Grading,

JD