Class: XiamiRadio::Radio
- Inherits:
-
Object
- Object
- XiamiRadio::Radio
- Defined in:
- lib/xiami_radio/radio.rb
Overview
There is a radio as you saw
Constant Summary collapse
- TRACKS_PATH =
'/radio/xml/type/%{type}/id/%{oid}'
- RADIO_PATH =
'/radio/play/type/%{type}/oid/%{oid}'
- XIAMI_CAI =
{type: 8, oid: 0}.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#nori ⇒ Object
readonly
Returns the value of attribute nori.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#play_queue ⇒ Object
readonly
Returns the value of attribute play_queue.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #get_new_playlist ⇒ Object
- #headers_referer ⇒ Object
-
#initialize(type:, oid:) ⇒ Radio
constructor
A new instance of Radio.
- #next_track ⇒ Object
Constructor Details
#initialize(type:, oid:) ⇒ Radio
Returns a new instance of Radio.
11 12 13 14 15 16 17 |
# File 'lib/xiami_radio/radio.rb', line 11 def initialize(type:, oid:) @type = type @oid = oid @client = Client.new user: User.instance @nori = Nori.new(:convert_tags_to => -> (tag) { tag.snakecase.to_sym }) @play_queue = [] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/xiami_radio/radio.rb', line 9 def client @client end |
#nori ⇒ Object (readonly)
Returns the value of attribute nori.
9 10 11 |
# File 'lib/xiami_radio/radio.rb', line 9 def nori @nori end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
9 10 11 |
# File 'lib/xiami_radio/radio.rb', line 9 def oid @oid end |
#play_queue ⇒ Object (readonly)
Returns the value of attribute play_queue.
9 10 11 |
# File 'lib/xiami_radio/radio.rb', line 9 def play_queue @play_queue end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/xiami_radio/radio.rb', line 9 def type @type end |
Instance Method Details
#get_new_playlist ⇒ Object
19 20 21 22 |
# File 'lib/xiami_radio/radio.rb', line 19 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 ⇒ Object
29 30 31 32 |
# File 'lib/xiami_radio/radio.rb', line 29 def headers_referer referer = client.uri(path: RADIO_PATH % {type: type, oid: oid}).to_s {'Referer': referer} end |
#next_track ⇒ Object
24 25 26 27 |
# File 'lib/xiami_radio/radio.rb', line 24 def next_track @play_queue += get_new_playlist if @play_queue.size < 2 @play_queue.shift end |