Created
August 13, 2010 17:19
-
-
Save BinaryMuse/523223 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
~/src/youtube/vids |
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 | |
# Output directory is in .zelda | |
# Refactoring could include code to look for ~/.zelda, etc. | |
configFile = File.new ".zelda" | |
outputDir = File.expand_path configFile.readline.strip | |
configFile.close | |
# Check configuration. | |
raise "Episodes list not found at episodes.txt" if !File.exists? "episodes.txt" | |
raise "Invalid output directory - #{outputDir}" if !File.directory? outputDir | |
raise "Cannot write to output directory - #{outputDir}" if !File.writable? outputDir | |
# Print our output directory. | |
puts "Output directory is: #{outputDir}" | |
# Read each line of the episodes list via a block. | |
# Block ensures file is closed even if exceptions escape. | |
File.foreach "episodes.txt" do |line| | |
options = line.strip.split "," | |
# Verify the options split into an array of 3 elements. | |
# Skip to the next line if it didn't. | |
if options.size != 3 | |
puts "Invalid options line: \"#{line.strip}\"" | |
next | |
end | |
# Define our variables. | |
episode = options[0] | |
part = options[1] | |
url = options[2] | |
episodeOutputDir = "#{outputDir}/ep#{episode}" | |
episodeFile = "#{episodeOutputDir}/part#{part}.mp4" | |
# DO WORK! (If we need to) | |
Dir.mkdir episodeOutputDir unless File.directory? episodeOutputDir | |
system "youtube-dl -o #{episodeFile} \"#{url}\"" unless File.exists? episodeFile | |
end | |
# Notes on xxxx if yyyy vs xxxx unless yyyy | |
# I like to use xxxx if yyyy if yyyy is an exceptional case, and usually xxxx wouldn't be executed | |
# e.g. "Only do X if Y condition exists" - like the exceptions at the top of the file | |
# I like to use xxxx unless yyyy if xxxx is the usual action, and not doing it is exceptional | |
# e.g. "Do X, except don't do it if Y condition exists" - like the last couple lines of code |
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
1,2 | |
2,3,http://www.youtube.com/watch?v=q6g2jyBdpc0&feature=related | |
3,1,http://www.youtube.com/watch?v=bDHAUrqhokA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment