Class: StandFm

Inherits:
WebRadio show all
Defined in:
lib/standfm.rb

Instance Method Summary collapse

Methods inherited from WebRadio

instance

Constructor Details

#initialize(params, options) ⇒ StandFm

Returns a new instance of StandFm.



7
8
9
10
# File 'lib/standfm.rb', line 7

def initialize(params, options)
	super
	@offset = 0
end

Instance Method Details

#downloadObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/standfm.rb', line 12

def download
	uri = URI(@url)
	html = Nokogiri(uri.open.read)
	episode = uri + html.css('#root a[href^="/episodes/"]').map{|e|e.attr('href')}.uniq[@offset]

	html = episode.open.read
	json = JSON.parse(html.scan(%r[<script>window.__SERVER_STATE__=(.*)</script>]).flatten[0])
	m4a = json['topics'].find{|k,v|v['episodeId'] == File.basename(episode.path)}.last['downloadUrl']

	doc = Nokogiri(html)
	serial = doc.title.scan(/#(\d+)/).flatten.first.to_i
	@cover = doc.css('meta[property="og:image"]').attr('content').text unless @cover
	m4a_file = "#{@label}##{serial}.m4a"
	mp3_file = "#{@label}##{serial}.mp3"

	mp3nize(m4a_file, mp3_file) do
		open(m4a_file, 'wb:ASCII-8BIT') do |w|
			w.write(URI(m4a).open.read)
		end
	end
end

#dumpObject



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

def dump
	uri = URI(@url)
	tag = File.basename(uri.path)
	html = Nokogiri(uri.open.read)
	label, = html.css('title').text.split(/ \| /)
	cover = html.css('meta[property="og:image"]').attr('content').text
	return {
		tag => {
			'desc' => label,
			'url' => @url,
			'label' => label,
			'cover' => cover
		}
	}
end