Class: Onsen

Inherits:
HLS show all
Defined in:
lib/onsen.rb

Constant Summary collapse

HEADERS =
{
	"Referer" => 'https://www.onsen.ag/'
}

Instance Method Summary collapse

Methods inherited from WebRadio

instance

Constructor Details

#initialize(params, options) ⇒ Onsen

Returns a new instance of Onsen.



12
13
14
15
16
# File 'lib/onsen.rb', line 12

def initialize(params, options)
	super
	@cover = "//*[@class='newest-content--left']//img[1]/@src" unless @cover
	@offset = 0
end

Instance Method Details

#downloadObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/onsen.rb', line 18

def download
	program = File.basename(URI(@url).path)
	html = URI.open(@url, HEADERS, &:read)
	serial = 0
	Nokogiri(html).css('.play-video-info tr').each do |tr|
		begin
			serial = tr.css('td')[0].text.scan(/\d+/)[0].to_i
		rescue NoMethodError
			next # the header of tables
		end
		break unless serial == 0
	end
	m3u8 = html.gsub(%r[\\u002F], '/').scan(%r|"(https:[^:]*?.m3u8)"|).flatten.select{|m|
		m.match(%r|/\d+/#{program}.*?-#{serial}\.mp4|)
	}.first
	hls_download(@label, serial, m3u8, HEADERS)
end

#dumpObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/onsen.rb', line 36

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