Sha256: 1197e97620b97e03fa686701f5e0a57cc0cbba7899b4cc0a0b78bfe3963d0bd6

Contents?: true

Size: 1.13 KB

Versions: 32

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

require 'webradio'
require 'nokogiri'

class Onsen < WebRadio
	def initialize(params, options)
		super
		@cover = "//*[@id='newProgramWrap']//img[1]/@src" unless @cover
	end

	def download
		onsen_download(@label, @url.scan(%r|/([^/]*)/$|).flatten.first)
	end

	def dump
		tag = Pathname(@url).basename.to_s.gsub(%r|[-/]|, '_')
		html = Nokogiri(open(@url, &:read))
		title = html.css('#outLineWrap h1').text
		return {
			tag => {
				'desc' => title,
				'url' => @url,
				'label' => tag
			}
		}
	end

private
	def onsen_download(name, program_id)
		html = Nokogiri(open('http://onsen.ag/', 'User-Agent' => 'iPhone', &:read))
		begin
			serial = html.css("##{program_id}").text.scan(/#(\d+)/).flatten.first
			mp3_url = html.css('form[target=_self]').select {|form|
				form.attr('action') =~ %r[/#{program_id}\w+\.mp3]
			}.first.attr('action')
		rescue NoMethodError
			raise NotFoundError.new("no radio program in #{program_id}.")
		end
		mp3_file = "#{name}##{serial}.mp3"
		mp3nize(mp3_file, mp3_file, false) do
			open(mp3_file, 'wb:ASCII-8BIT') do |mp3|
				mp3.write open(mp3_url, 'rb:ASCII-8BIT', &:read)
			end
		end
	end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rget-4.8.1 lib/onsen.rb
rget-4.8.0 lib/onsen.rb
rget-4.7.9 lib/onsen.rb
rget-4.7.8 lib/onsen.rb
rget-4.7.7 lib/onsen.rb
rget-4.7.6 lib/onsen.rb
rget-4.7.5 lib/onsen.rb
rget-4.7.4 lib/onsen.rb
rget-4.7.3 lib/onsen.rb
rget-4.7.2 lib/onsen.rb
rget-4.7.1 lib/onsen.rb
rget-4.7.0 lib/onsen.rb
rget-4.6.1 lib/onsen.rb
rget-4.6.0 lib/onsen.rb
rget-4.5.0 lib/onsen.rb
rget-4.4.1 lib/onsen.rb
rget-4.4.0 lib/onsen.rb
rget-4.3.5 lib/onsen.rb
rget-4.3.4 lib/onsen.rb
rget-4.3.3 lib/onsen.rb