Sha256: afde212cd301c070f6338345e570146da455a3d17c07c0e484884d5f7147d863

Contents?: true

Size: 762 Bytes

Versions: 35

Compression:

Stored size: 762 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(open(episode.enclosure.url, 'rb:ASCII-8BIT', &:read))
		end
		puts "done."
	end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
rget-4.8.4 lib/podcast.rb
rget-4.8.3 lib/podcast.rb
rget-4.8.2 lib/podcast.rb
rget-4.8.1 lib/podcast.rb
rget-4.8.0 lib/podcast.rb
rget-4.7.9 lib/podcast.rb
rget-4.7.8 lib/podcast.rb
rget-4.7.7 lib/podcast.rb
rget-4.7.6 lib/podcast.rb
rget-4.7.5 lib/podcast.rb
rget-4.7.4 lib/podcast.rb
rget-4.7.3 lib/podcast.rb
rget-4.7.2 lib/podcast.rb
rget-4.7.1 lib/podcast.rb
rget-4.7.0 lib/podcast.rb
rget-4.6.1 lib/podcast.rb
rget-4.6.0 lib/podcast.rb
rget-4.5.0 lib/podcast.rb
rget-4.4.1 lib/podcast.rb
rget-4.4.0 lib/podcast.rb