Created
August 13, 2012 09:28
-
-
Save tansengming/3338651 to your computer and use it in GitHub Desktop.
download.rake
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
| namespace :download do | |
| DownloadPath = Pathname.new('Downloads') | |
| ListFile = DownloadPath + 'list' | |
| task :all do | |
| ListFiles = Pathname.glob('Downloads/**/list') | |
| next if ListFiles.empty? | |
| ListFiles.each do |listfile| | |
| list = listfile.read.split.compact.reject(&:empty?) | |
| while list.any? | |
| url = list.shift | |
| cd listfile.dirname do | |
| if url[/(vimeo|youtube)\.com/] | |
| sh "youtube-dl -lic --format 38/37/22/35/34/18/6/5/17/13 '#{url}'" | |
| else | |
| Cocaine::CommandLine.new("wget", "-c -U 'QuickTime/7.6.2' '#{url}'").run | |
| end | |
| end | |
| File.open(listfile, 'w') {|f| f.write list.join("\n")} | |
| end | |
| listfile.delete | |
| end | |
| end | |
| task :fix_filenames do | |
| cd DownloadPath do | |
| Pathname.glob('makeplaylist.*').reject{|p| p.to_s[/mp4$/]}.each do |f| | |
| f.rename(f.to_s + '.mp4') | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment