Class: Caldera::Model::Track
- Inherits:
-
Object
- Object
- Caldera::Model::Track
- Defined in:
- lib/caldera/model/track.rb
Instance Attribute Summary collapse
- #author ⇒ Object readonly
- #identifier ⇒ Object readonly
- #length ⇒ Object readonly
- #position ⇒ Object readonly
- #seekable ⇒ Object readonly
- #stream ⇒ Object readonly
- #title ⇒ Object readonly
- #track_data ⇒ Object readonly
- #uri ⇒ Object readonly
Class Method Summary collapse
-
.from_b64(b64_data) ⇒ Object
Decode a track from base64 track data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Track
constructor
A new instance of Track.
Constructor Details
#initialize(data) ⇒ Track
Returns a new instance of Track.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/caldera/model/track.rb', line 35 def initialize(data) # track_data could maybe use a better name. It's # a base64 representation of a binary data representation # of a track= @track_data = data['track'] info = data['info'] @identifier = info['identifier'] @seekable = info['isSeekable'] @author = info['author'] @length = info['length'] @stream = info['isStream'] @position = info['position'] @title = info['title'] @uri = info['uri'] @source = info['source'] end |
Instance Attribute Details
#author ⇒ Object (readonly)
18 19 20 |
# File 'lib/caldera/model/track.rb', line 18 def @author end |
#identifier ⇒ Object (readonly)
12 13 14 |
# File 'lib/caldera/model/track.rb', line 12 def identifier @identifier end |
#length ⇒ Object (readonly)
21 22 23 |
# File 'lib/caldera/model/track.rb', line 21 def length @length end |
#position ⇒ Object (readonly)
27 28 29 |
# File 'lib/caldera/model/track.rb', line 27 def position @position end |
#seekable ⇒ Object (readonly)
15 16 17 |
# File 'lib/caldera/model/track.rb', line 15 def seekable @seekable end |
#stream ⇒ Object (readonly)
24 25 26 |
# File 'lib/caldera/model/track.rb', line 24 def stream @stream end |
#title ⇒ Object (readonly)
30 31 32 |
# File 'lib/caldera/model/track.rb', line 30 def title @title end |
#track_data ⇒ Object (readonly)
9 10 11 |
# File 'lib/caldera/model/track.rb', line 9 def track_data @track_data end |
#uri ⇒ Object (readonly)
33 34 35 |
# File 'lib/caldera/model/track.rb', line 33 def uri @uri end |
Class Method Details
.from_b64(b64_data) ⇒ Object
Decode a track from base64 track data.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/caldera/model/track.rb', line 55 def self.from_b64(b64_data) data = Base64.decode64(b64_data) flags, version = data.unpack('NC') raise 'Unsupported track data' if (flags >> 30) != 1 # This is gross but it's easier than not doing it case version when 1 title, , length, identifier, is_stream, source = data.unpack('@7Z*xZ*Q>xZ*CxZ*') Track.new( 'track' => b64_data, 'info' => { 'title' => title, 'author' => , 'length' => length, 'identifier' => identifier, 'isStream' => is_stream == 1, 'source' => source } ) when 2 title, , length, identifier, is_stream, uri, source = data.unpack('@7Z*xZ*Q>xZ*CxxZ*xZ*xZ*') Track.new( 'track' => b64_data, 'info' => { 'title' => title, 'author' => , 'length' => length, 'identifier' => identifier, 'isStream' => is_stream == 1, 'source' => source, 'uri' => uri } ) else raise 'Unsupported track version' end end |