Class: Himalaya

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

Instance Method Summary collapse

Methods inherited from WebRadio

#dump, instance

Constructor Details

#initialize(params, options) ⇒ Himalaya

Returns a new instance of Himalaya.



5
6
7
8
# File 'lib/himalaya.rb', line 5

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

Instance Method Details

#downloadObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/himalaya.rb', line 10

def download
	html = URI.open(@url).read
	json_str = html.scan(/__NEXT_DATA__ = (.*)/).flatten.first
	json = JSON.parse(json_str)
	tracks = json['props']['seo']['albumData']['data']['tracks']['list']
	track = tracks[@offset]

	m4a_url = track['playPathAacv164']
	serial = Time.at(track['createdAt']/1000).strftime('%Y%m%d')
	@cover ||= track['coverLarge']

	m4a_file = "#{@label}##{serial}.m4a"
	mp3_file = "#{@label}##{serial}.mp3"
	mp3nize(m4a_file, mp3_file) do
		open(m4a_file, 'wb:ASCII-8BIT') do |m4a|
			m4a.write(URI.open(m4a_url).read)
		end
	end
end