Sha256: 5480fe1bb8b1ed311e08a279366f5da385c04f67520022a4b8cba2e803f2e2af
Contents?: true
Size: 766 Bytes
Versions: 11
Compression:
Stored size: 766 Bytes
Contents
# encoding: utf-8 require 'rss' class Podcast def initialize(url, options) @url = url @options = options yield self if block_given? end def download rss = RSS::Parser.parse(@url) label = @label || rss.channel.title episode = rss.items.first serial = episode.link.scan(%r|\d+[^/\.]*|).flatten.first if serial.to_i > 2000 # may be year serial = episode.pubDate.strftime('%Y%m%d') end unless serial puts "fail: recent episode not found." return end file = "#{label}##{serial}.mp3" if File.exist? file puts "'#{file}' is existent. skipped." return end print "getting #{serial}..." open(file, 'wb:ASCII-8BIT') do |o| o.write(URI.open(episode.enclosure.url, 'rb:ASCII-8BIT', &:read)) end puts "done." end end
Version data entries
11 entries across 11 versions & 1 rubygems