Sha256: 0a9b194b2cfccd97de83a82b39696d215a6a6e48cfd2937981464023f73d5f42

Contents?: true

Size: 698 Bytes

Versions: 11

Compression:

Stored size: 698 Bytes

Contents

# encoding: utf-8

require 'webradio'
require 'nokogiri'

class Onsen < WebRadio
	def download(name)
		onsen_download(name, @url.scan(%r|/([^/]*)/$|).flatten.first)
	end

private
	def onsen_download(name, program_id)
		html = Nokogiri(open('http://onsen.ag/', 'User-Agent' => 'iPhone', &:read))
		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')
		mp3_file = "#{name}##{serial}.mp3"
		mp3ize(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

11 entries across 11 versions & 1 rubygems

Version Path
rget-2.3.2 lib/onsen.rb
rget-2.3.1 lib/onsen.rb
rget-2.3.0 lib/onsen.rb
rget-2.2.4 lib/onsen.rb
rget-2.2.3 lib/onsen.rb
rget-2.2.2 lib/onsen.rb
rget-2.2.1 lib/onsen.rb
rget-2.2.0 lib/onsen.rb
rget-2.1.1 lib/onsen.rb
rget-2.1.0 lib/onsen.rb
rget-2.0.0 lib/onsen.rb