class XiamiRadio::Radio
There is a radio as you saw
Constants
- RADIO_PATH
- TRACKS_PATH
- XIAMI_CAI
Attributes
client[R]
oid[R]
play_queue[R]
type[R]
Public Class Methods
new(type:, oid:)
click to toggle source
# File lib/xiami_radio/radio.rb, line 11 def initialize(type:, oid:) @type = type @oid = oid @client = Client.new user: User.instance @play_queue = [] end
Public Instance Methods
get_new_playlist()
click to toggle source
# File lib/xiami_radio/radio.rb, line 18 def get_new_playlist tracks = client.get(uri, format: :xml, headers: headers_referer).dig(:play_list, :track_list, :track) tracks.map { |track| Track.new track, radio: self } end
headers_referer()
click to toggle source
# File lib/xiami_radio/radio.rb, line 28 def headers_referer referer = client.uri(path: RADIO_PATH % {type: type, oid: oid}).to_s {'Referer': referer} end
next_track()
click to toggle source
# File lib/xiami_radio/radio.rb, line 23 def next_track @play_queue += get_new_playlist if @play_queue.size < 2 @play_queue.shift end
Private Instance Methods
uri()
click to toggle source
# File lib/xiami_radio/radio.rb, line 35 def uri client.uri path: TRACKS_PATH % {type: type, oid: oid}, query: URI.encode_www_form(v: Time.now.to_i) end