Class: SkyJam::Track
- Inherits:
-
Object
- Object
- SkyJam::Track
- Defined in:
- lib/skyjam/track.rb
Defined Under Namespace
Modules: Source
Instance Attribute Summary collapse
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#album_artist ⇒ Object
readonly
Returns the value of attribute album_artist.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #data(remote: false) ⇒ Object
- #dirname ⇒ Object
- #download(lazy: false) ⇒ Object
- #extname ⇒ Object
- #filename ⇒ Object
-
#initialize(info) ⇒ Track
constructor
A new instance of Track.
- #local? ⇒ Boolean
- #path ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(info) ⇒ Track
Returns a new instance of Track.
19 20 21 22 23 24 25 26 27 |
# File 'lib/skyjam/track.rb', line 19 def initialize(info) @id = info[:id] @title = info[:title] @album = info[:album] @album_artist = info[:album_artist] unless info[:album_artist].nil? || info[:album_artist].empty? @artist = info[:artist] @number = info[:track_number] @size = info[:track_size] end |
Instance Attribute Details
#album ⇒ Object (readonly)
Returns the value of attribute album.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def album @album end |
#album_artist ⇒ Object (readonly)
Returns the value of attribute album_artist.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def album_artist @album_artist end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def artist @artist end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def id @id end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def number @number end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def size @size end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/skyjam/track.rb', line 11 def title @title end |
Instance Method Details
#data(remote: false) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/skyjam/track.rb', line 67 def data(remote: false) if remote || !local? url = client.download_url(id) client.download_track(url) else File.binread(path) end end |
#dirname ⇒ Object
37 38 39 40 41 42 |
# File 'lib/skyjam/track.rb', line 37 def dirname path_components = [library.path, escape_path_component(album_artist || artist), escape_path_component(album)] File.join(path_components) end |
#download(lazy: false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/skyjam/track.rb', line 52 def download(lazy: false) return if !lazy || (lazy && local?) file = Tempfile.new(filename) begin file << data(remote: true) rescue SkyJam::Client::Error file.close! raise else make_dir FileUtils.mv(file.path, path) end end |
#extname ⇒ Object
33 34 35 |
# File 'lib/skyjam/track.rb', line 33 def extname '.mp3' end |
#filename ⇒ Object
29 30 31 |
# File 'lib/skyjam/track.rb', line 29 def filename escape_path_component("%02d - #{title}" % number) << extname end |
#local? ⇒ Boolean
48 49 50 |
# File 'lib/skyjam/track.rb', line 48 def local? File.exist?(path) end |
#path ⇒ Object
44 45 46 |
# File 'lib/skyjam/track.rb', line 44 def path File.join(dirname, filename) end |
#upload ⇒ Object
76 77 78 |
# File 'lib/skyjam/track.rb', line 76 def upload fail NotImplementedError end |