Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use curl instead of wget; support subscript account rss feed #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions railscasts_downloader.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/usr/bin/ruby
require 'rss'

p 'Downloading rss index'
# PUT in your subscription account's rss feed. You can find it at
# Magaging Subscription/RSS Feeds after logging Railscasts.com
SUBSCRIBED_FEED = ENV['RAILSCASTS_SUB_RSS_FEED'] || nil

rss_string = open('http://feeds.feedburner.com/railscasts').read
puts 'Downloading rss index'
rss_feed = SUBSCRIBED_FEED || 'http://feeds.feedburner.com/railscasts'
rss_string = open(rss_feed).read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse

videos_filenames = videos_urls.map {|url| url.split('/').last }
existing_filenames = Dir.glob('*.mp4')
missing_filenames = videos_filenames - existing_filenames
p "Downloading #{missing_filenames.size} missing videos"
puts "Downloading #{missing_filenames.size} missing videos"

missing_videos_urls = videos_urls.select { |video_url| missing_filenames.any? { |filename| video_url.match filename } }



missing_videos_urls.each do |video_url|
filename = video_url.split('/').last
p filename
p %x(wget -c #{video_url} -O #{filename}.tmp )
p %x(mv #{filename}.tmp #{filename} )
puts filename
download_success = system("curl -C - #{video_url} -o #{filename}.tmp")
rename_success = system("mv #{filename}.tmp #{filename}")
if download_success && rename_success
puts "Download #{filename} success!"
puts
else
puts "Something went wrong..."
end
end
p 'Finished synchronization'
puts 'Finished synchronization'