Class: Podcast
- Inherits:
-
Object
- Object
- Podcast
- Defined in:
- lib/podcast.rb
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(url, options) {|_self| ... } ⇒ Podcast
constructor
A new instance of Podcast.
Constructor Details
#initialize(url, options) {|_self| ... } ⇒ Podcast
Returns a new instance of Podcast.
6 7 8 9 10 |
# File 'lib/podcast.rb', line 6 def initialize(url, ) @url = url @options = yield self if block_given? end |
Instance Method Details
#download ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/podcast.rb', line 12 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(open(episode.enclosure.url, 'rb:ASCII-8BIT', &:read)) end puts "done." end |