Class: MusicBox::Catalog::Release
- Inherits:
-
Group::Item
- Object
- Group::Item
- MusicBox::Catalog::Release
- Defined in:
- lib/musicbox/catalog/release.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
linked on load.
-
#artists ⇒ Object
Returns the value of attribute artists.
-
#artists_sort ⇒ Object
Returns the value of attribute artists_sort.
-
#blocked_from_sale ⇒ Object
Returns the value of attribute blocked_from_sale.
-
#community ⇒ Object
Returns the value of attribute community.
-
#companies ⇒ Object
Returns the value of attribute companies.
-
#country ⇒ Object
Returns the value of attribute country.
-
#data_quality ⇒ Object
Returns the value of attribute data_quality.
-
#date_added ⇒ Object
Returns the value of attribute date_added.
-
#date_changed ⇒ Object
Returns the value of attribute date_changed.
-
#estimated_weight ⇒ Object
Returns the value of attribute estimated_weight.
-
#extraartists ⇒ Object
Returns the value of attribute extraartists.
-
#format_quantity ⇒ Object
Returns the value of attribute format_quantity.
-
#formats ⇒ Object
Returns the value of attribute formats.
-
#genres ⇒ Object
Returns the value of attribute genres.
-
#identifiers ⇒ Object
Returns the value of attribute identifiers.
-
#images ⇒ Object
Returns the value of attribute images.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#lowest_price ⇒ Object
Returns the value of attribute lowest_price.
-
#main_release ⇒ Object
Returns the value of attribute main_release.
-
#main_release_url ⇒ Object
Returns the value of attribute main_release_url.
-
#master ⇒ Object
linked on load.
-
#master_id ⇒ Object
Returns the value of attribute master_id.
-
#master_url ⇒ Object
Returns the value of attribute master_url.
-
#most_recent_release ⇒ Object
Returns the value of attribute most_recent_release.
-
#most_recent_release_url ⇒ Object
Returns the value of attribute most_recent_release_url.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#num_for_sale ⇒ Object
Returns the value of attribute num_for_sale.
-
#released ⇒ Object
Returns the value of attribute released.
-
#released_formatted ⇒ Object
Returns the value of attribute released_formatted.
-
#resource_url ⇒ Object
Returns the value of attribute resource_url.
-
#series ⇒ Object
Returns the value of attribute series.
-
#status ⇒ Object
Returns the value of attribute status.
-
#styles ⇒ Object
Returns the value of attribute styles.
-
#thumb ⇒ Object
Returns the value of attribute thumb.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tracklist ⇒ Object
Returns the value of attribute tracklist.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#versions_url ⇒ Object
Returns the value of attribute versions_url.
-
#videos ⇒ Object
Returns the value of attribute videos.
-
#year ⇒ Object
Returns the value of attribute year.
Attributes inherited from Group::Item
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #artist ⇒ Object
- #artist_key ⇒ Object
- #cd? ⇒ Boolean
- #details_to_s ⇒ Object
- #download_image(uri:, file:) ⇒ Object
- #download_images ⇒ Object
- #link_images(images_dir) ⇒ Object
- #original_release_year ⇒ Object
- #release_year ⇒ Object
- #select_cover ⇒ Object
- #sort_tuple ⇒ Object
- #summary_to_s ⇒ Object
- #to_csv ⇒ Object
- #to_label ⇒ Object
- #to_s ⇒ Object
- #tracklist_flattened(tracklist = nil) ⇒ Object
- #tracklist_to_info(tracklist = nil) ⇒ Object
Methods inherited from Group::Item
#fields, #info_file, #initialize, load, #save, #serialize
Constructor Details
This class inherits a constructor from MusicBox::Group::Item
Instance Attribute Details
#album ⇒ Object
linked on load
47 48 49 |
# File 'lib/musicbox/catalog/release.rb', line 47 def album @album end |
#artists ⇒ Object
Returns the value of attribute artists.
7 8 9 |
# File 'lib/musicbox/catalog/release.rb', line 7 def artists @artists end |
#artists_sort ⇒ Object
Returns the value of attribute artists_sort.
8 9 10 |
# File 'lib/musicbox/catalog/release.rb', line 8 def artists_sort @artists_sort end |
#blocked_from_sale ⇒ Object
Returns the value of attribute blocked_from_sale.
9 10 11 |
# File 'lib/musicbox/catalog/release.rb', line 9 def blocked_from_sale @blocked_from_sale end |
#community ⇒ Object
Returns the value of attribute community.
10 11 12 |
# File 'lib/musicbox/catalog/release.rb', line 10 def community @community end |
#companies ⇒ Object
Returns the value of attribute companies.
11 12 13 |
# File 'lib/musicbox/catalog/release.rb', line 11 def companies @companies end |
#country ⇒ Object
Returns the value of attribute country.
12 13 14 |
# File 'lib/musicbox/catalog/release.rb', line 12 def country @country end |
#data_quality ⇒ Object
Returns the value of attribute data_quality.
13 14 15 |
# File 'lib/musicbox/catalog/release.rb', line 13 def data_quality @data_quality end |
#date_added ⇒ Object
Returns the value of attribute date_added.
14 15 16 |
# File 'lib/musicbox/catalog/release.rb', line 14 def date_added @date_added end |
#date_changed ⇒ Object
Returns the value of attribute date_changed.
15 16 17 |
# File 'lib/musicbox/catalog/release.rb', line 15 def date_changed @date_changed end |
#estimated_weight ⇒ Object
Returns the value of attribute estimated_weight.
16 17 18 |
# File 'lib/musicbox/catalog/release.rb', line 16 def estimated_weight @estimated_weight end |
#extraartists ⇒ Object
Returns the value of attribute extraartists.
17 18 19 |
# File 'lib/musicbox/catalog/release.rb', line 17 def extraartists @extraartists end |
#format_quantity ⇒ Object
Returns the value of attribute format_quantity.
18 19 20 |
# File 'lib/musicbox/catalog/release.rb', line 18 def format_quantity @format_quantity end |
#formats ⇒ Object
Returns the value of attribute formats.
19 20 21 |
# File 'lib/musicbox/catalog/release.rb', line 19 def formats @formats end |
#genres ⇒ Object
Returns the value of attribute genres.
20 21 22 |
# File 'lib/musicbox/catalog/release.rb', line 20 def genres @genres end |
#identifiers ⇒ Object
Returns the value of attribute identifiers.
21 22 23 |
# File 'lib/musicbox/catalog/release.rb', line 21 def identifiers @identifiers end |
#images ⇒ Object
Returns the value of attribute images.
22 23 24 |
# File 'lib/musicbox/catalog/release.rb', line 22 def images @images end |
#labels ⇒ Object
Returns the value of attribute labels.
23 24 25 |
# File 'lib/musicbox/catalog/release.rb', line 23 def labels @labels end |
#lowest_price ⇒ Object
Returns the value of attribute lowest_price.
24 25 26 |
# File 'lib/musicbox/catalog/release.rb', line 24 def lowest_price @lowest_price end |
#main_release ⇒ Object
Returns the value of attribute main_release.
25 26 27 |
# File 'lib/musicbox/catalog/release.rb', line 25 def main_release @main_release end |
#main_release_url ⇒ Object
Returns the value of attribute main_release_url.
26 27 28 |
# File 'lib/musicbox/catalog/release.rb', line 26 def main_release_url @main_release_url end |
#master ⇒ Object
linked on load
46 47 48 |
# File 'lib/musicbox/catalog/release.rb', line 46 def master @master end |
#master_id ⇒ Object
Returns the value of attribute master_id.
27 28 29 |
# File 'lib/musicbox/catalog/release.rb', line 27 def master_id @master_id end |
#master_url ⇒ Object
Returns the value of attribute master_url.
28 29 30 |
# File 'lib/musicbox/catalog/release.rb', line 28 def master_url @master_url end |
#most_recent_release ⇒ Object
Returns the value of attribute most_recent_release.
29 30 31 |
# File 'lib/musicbox/catalog/release.rb', line 29 def most_recent_release @most_recent_release end |
#most_recent_release_url ⇒ Object
Returns the value of attribute most_recent_release_url.
30 31 32 |
# File 'lib/musicbox/catalog/release.rb', line 30 def most_recent_release_url @most_recent_release_url end |
#notes ⇒ Object
Returns the value of attribute notes.
31 32 33 |
# File 'lib/musicbox/catalog/release.rb', line 31 def notes @notes end |
#num_for_sale ⇒ Object
Returns the value of attribute num_for_sale.
32 33 34 |
# File 'lib/musicbox/catalog/release.rb', line 32 def num_for_sale @num_for_sale end |
#released ⇒ Object
Returns the value of attribute released.
33 34 35 |
# File 'lib/musicbox/catalog/release.rb', line 33 def released @released end |
#released_formatted ⇒ Object
Returns the value of attribute released_formatted.
34 35 36 |
# File 'lib/musicbox/catalog/release.rb', line 34 def released_formatted @released_formatted end |
#resource_url ⇒ Object
Returns the value of attribute resource_url.
35 36 37 |
# File 'lib/musicbox/catalog/release.rb', line 35 def resource_url @resource_url end |
#series ⇒ Object
Returns the value of attribute series.
36 37 38 |
# File 'lib/musicbox/catalog/release.rb', line 36 def series @series end |
#status ⇒ Object
Returns the value of attribute status.
37 38 39 |
# File 'lib/musicbox/catalog/release.rb', line 37 def status @status end |
#styles ⇒ Object
Returns the value of attribute styles.
38 39 40 |
# File 'lib/musicbox/catalog/release.rb', line 38 def styles @styles end |
#thumb ⇒ Object
Returns the value of attribute thumb.
39 40 41 |
# File 'lib/musicbox/catalog/release.rb', line 39 def thumb @thumb end |
#title ⇒ Object
Returns the value of attribute title.
41 42 43 |
# File 'lib/musicbox/catalog/release.rb', line 41 def title @title end |
#tracklist ⇒ Object
Returns the value of attribute tracklist.
40 41 42 |
# File 'lib/musicbox/catalog/release.rb', line 40 def tracklist @tracklist end |
#uri ⇒ Object
Returns the value of attribute uri.
42 43 44 |
# File 'lib/musicbox/catalog/release.rb', line 42 def uri @uri end |
#versions_url ⇒ Object
Returns the value of attribute versions_url.
43 44 45 |
# File 'lib/musicbox/catalog/release.rb', line 43 def versions_url @versions_url end |
#videos ⇒ Object
Returns the value of attribute videos.
44 45 46 |
# File 'lib/musicbox/catalog/release.rb', line 44 def videos @videos end |
#year ⇒ Object
Returns the value of attribute year.
45 46 47 |
# File 'lib/musicbox/catalog/release.rb', line 45 def year @year end |
Class Method Details
.csv_header ⇒ Object
49 50 51 |
# File 'lib/musicbox/catalog/release.rb', line 49 def self.csv_header %w[ID year artist title].to_csv end |
Instance Method Details
#<=>(other) ⇒ Object
101 102 103 |
# File 'lib/musicbox/catalog/release.rb', line 101 def <=>(other) sort_tuple <=> other.sort_tuple end |
#artist ⇒ Object
93 94 95 |
# File 'lib/musicbox/catalog/release.rb', line 93 def artist ReleaseArtist.artists_to_s(@artists) end |
#artist_key ⇒ Object
97 98 99 |
# File 'lib/musicbox/catalog/release.rb', line 97 def artist_key @artists.first.key end |
#cd? ⇒ Boolean
89 90 91 |
# File 'lib/musicbox/catalog/release.rb', line 89 def cd? @formats.find(&:cd?) != nil end |
#details_to_s ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/musicbox/catalog/release.rb', line 130 def details_to_s info = [ ['ID', @id], ['Master ID', @master_id || '-'], ['Artist', ReleaseArtist.artists_to_s(@artists)], ['Title', @title], ['Formats', Format.to_s(@formats)], ['Released', release_year || '-'], ['Originally released', original_release_year || '-'], ['Discogs URI', @uri || '-'], ['Album dir', @album&.dir || '-'], ['Tracks', nil, tracklist_to_info], ] MusicBox.info_to_s(info) end |
#download_image(uri:, file:) ⇒ Object
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/musicbox/catalog/release.rb', line 205 def download_image(uri:, file:) if uri && file unless file.exist? puts "#{@id}: downloading #{uri}" file.dirname.mkpath unless file.dirname.exist? file.write(HTTP.get(uri)) sleep(1) end end end |
#download_images ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/musicbox/catalog/release.rb', line 193 def download_images image = @images.find { |image| image['type'] == 'primary' } if image download_image(uri: image['uri'], file: image['file']) else @images.each do |image| download_image(uri: image['uri'], file: image['file']) end end @master.download_images if @master end |
#link_images(images_dir) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/musicbox/catalog/release.rb', line 184 def link_images(images_dir) if @images @images.each do |image| uri = URI.parse(image['uri']) image['file'] = images_dir / Path.new(uri.path).basename end end end |
#original_release_year ⇒ Object
85 86 87 |
# File 'lib/musicbox/catalog/release.rb', line 85 def original_release_year @master&.release_year || release_year end |
#release_year ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/musicbox/catalog/release.rb', line 77 def release_year if @year && @year != 0 @year elsif @released @released.to_s.split('-').first&.to_i end end |
#select_cover ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/musicbox/catalog/release.rb', line 216 def select_cover if @album.has_cover? puts "#{@id}: cover already exists" return end download_images @album.extract_cover choices = [ @master&.images&.map { |i| i['file'] }, @images&.map { |i| i['file'] }, @album.cover_file, ].flatten.compact.uniq.select(&:exist?) if choices.empty? puts "#{@id}: no covers exist" else choices.each { |f| run_command('open', f) } choice = TTY::Prompt.new.select('Cover?', choices) cover_file = (album.dir / 'cover').add_extension(choice.extname) choice.cp(cover_file) @album. end end |
#sort_tuple ⇒ Object
105 106 107 |
# File 'lib/musicbox/catalog/release.rb', line 105 def sort_tuple [artist_key, original_release_year || 0, @title] end |
#summary_to_s ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/musicbox/catalog/release.rb', line 117 def summary_to_s '%-8s | %1s%1s | %-4s %4s | %-50.50s | %-60.60s | %-6s' % [ @id, @album ? 'A' : '', @album&.has_cover? ? 'C' : '', artist_key, original_release_year || '-', artist, @title, Format.to_s(@formats), ] end |
#to_csv ⇒ Object
109 110 111 |
# File 'lib/musicbox/catalog/release.rb', line 109 def to_csv [@id, original_release_year, artist, @title].to_csv end |
#to_label ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/musicbox/catalog/release.rb', line 173 def to_label { artist: artist, title: title, key: artist_key, year: original_release_year, format: Format.to_s(@formats), id: id, } end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/musicbox/catalog/release.rb', line 113 def to_s summary_to_s end |
#tracklist_flattened(tracklist = nil) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/musicbox/catalog/release.rb', line 146 def tracklist_flattened(tracklist=nil) tracklist ||= @tracklist tracks = [] tracklist.each do |track| tracks << track tracks += tracklist_flattened(track.sub_tracks) if track.type == 'index' end tracks end |
#tracklist_to_info(tracklist = nil) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/musicbox/catalog/release.rb', line 156 def tracklist_to_info(tracklist=nil) tracklist ||= @tracklist max_position_length = tracklist.select(&:position).map { |t| t.position.to_s.length }.max tracklist.map do |track| [ track.type, [ !track.position.to_s.empty? ? ('%*s:' % [max_position_length, track.position]) : nil, track.title || '-', track.artists ? "(#{ReleaseArtist.artists_to_s(track.artists)})" : nil, !track.duration.to_s.empty? ? "[#{track.duration}]" : nil, ].compact.join(' '), track.sub_tracks ? tracklist_to_info(track.sub_tracks) : nil, ] end end |