Created
April 28, 2009 15:59
-
-
Save lp/103232 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # quick and dirty script for EDL cleaning | |
| # will process all files inside this script directory | |
| # insert some conditions or some processing in the certer iteration loop | |
| require 'find' | |
| require 'ftools' | |
| scriptfile = File.basename(__FILE__) | |
| Dir.chdir( File.dirname(__FILE__)) | |
| other_files = Array.new | |
| Find.find(File.dirname(__FILE__)) do |path| | |
| next if File.directory?(path) or File.basename(path) == scriptfile or File.basename(path)[0..0] == '.' | |
| other_files << path | |
| end | |
| puts "EDL Cleaner...\n(c) lp 2009\n" | |
| other_files.each do |path| | |
| basename = File.basename(path); dirname = File.dirname(path) | |
| puts "Processing file #{basename}" | |
| new_basename = 'CLEAN_' + basename; new_path = File.catname(new_basename,dirname) | |
| File.open(new_path,'w') do |newfile| | |
| File.open(path,'r') do |oldfile| | |
| oldfile.readlines.each do |content| | |
| # Insert condition or processing here | |
| if content =~ /TITLE:|FCM:/ | |
| # this leaves the edl title and fcm alone | |
| newfile.print(content) | |
| elsif content =~ /^\*/ | |
| # this one removes all lines starting with a star, i.e. comments | |
| puts "<< #{content} >> deleted (star)" | |
| elsif content =~ /^\s*$/ | |
| # this one removes empty lines | |
| puts "<< #{content} >> deleted (empty)" | |
| elsif (content =~ /^\d\d\d\s+AM/).nil? | |
| # this one removes any lines which sources does not match AM... (project specific) | |
| puts "<< #{content} >> deleted (not right source)" | |
| elsif content =~ /(\d\d:\d\d:\d\d:\d\d)\s+(\d\d:\d\d:\d\d:\d\d)\s+(\d\d:\d\d:\d\d:\d\d)\s+(\d\d:\d\d:\d\d:\d\d)\s+/ | |
| # this one removes any zero duration line | |
| if $1 == $2 && $3 == $4 | |
| puts "<< #{content} >> deleted (dupe TC)" | |
| else | |
| newfile.print(content) | |
| end | |
| else | |
| newfile.print(content) | |
| end | |
| end | |
| end | |
| end | |
| puts "substitution done for file #{basename}\nchanges were saved to file #{new_basename}\n\n" | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment