Skip to content

Instantly share code, notes, and snippets.

@alexventuraio
Forked from samqiu/railscasts.rb
Created December 9, 2016 03:43
Show Gist options
  • Save alexventuraio/69d3c2fe2355bb16142f3fd9cc38edd7 to your computer and use it in GitHub Desktop.
Save alexventuraio/69d3c2fe2355bb16142f3fd9cc38edd7 to your computer and use it in GitHub Desktop.

Revisions

  1. @samqiu samqiu revised this gist Jun 7, 2013. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions railscasts.rb
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,35 @@
    #!/usr/bin/ruby
    require 'rss'

    p 'Downloading rss index'
    # Usage
    # $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
    # episodes.rss
    # OR
    # $ ./railscasts.rb

    # Example: $ .railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/episodes.rss
    rss_url = ARGV.first ? ARGV.first : "http://feeds.feedburner.com/railscasts"
    p 'Downloading rss index'
    rss_url = ARGV.first ? ARGV.first : 'http://feeds.feedburner.com/railscasts'

    rss_string = open(rss_url).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 }
    videos_filenames = videos_urls.map { |url| url.split('/').last }
    existing_filenames = Dir.glob('*.mov')
    missing_filenames = videos_filenames - existing_filenames
    p "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 = 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
    next if File.exists? filename
    p filename

    p filename
    p %x(wget #{video_url} -O #{filename}.tmp )
    p %x(mv #{filename}.tmp #{filename} )
    end

    p 'Finished synchronization'
    p 'Finished synchronization'
  2. @samqiu samqiu renamed this gist Jun 7, 2013. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gistfile1.rb → railscasts.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,10 @@

    p 'Downloading rss index'

    rss_string = open('http://feeds.feedburner.com/railscasts').read
    # Example: $ .railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/episodes.rss
    rss_url = ARGV.first ? ARGV.first : "http://feeds.feedburner.com/railscasts"

    rss_string = open(rss_url).read
    rss = RSS::Parser.parse(rss_string, false)
    videos_urls = rss.items.map { |it| it.enclosure.url }.reverse

    @@ -13,12 +16,12 @@
    p "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
    next if File.exists? filename
    p filename
    p filename
    p %x(wget #{video_url} -O #{filename}.tmp )
    p %x(mv #{filename}.tmp #{filename} )
    end

    p 'Finished synchronization'
  3. @samqiu samqiu revised this gist Feb 27, 2013. No changes.
  4. @samqiu samqiu created this gist Dec 13, 2011.
    24 changes: 24 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/ruby
    require 'rss'

    p 'Downloading rss index'

    rss_string = open('http://feeds.feedburner.com/railscasts').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('*.mov')
    missing_filenames = videos_filenames - existing_filenames
    p "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
    next if File.exists? filename
    p filename
    p %x(wget #{video_url} -O #{filename}.tmp )
    p %x(mv #{filename}.tmp #{filename} )
    end
    p 'Finished synchronization'