class MusicBox::Catalog::Release
Attributes
album[RW]
artists[RW]
artists_sort[RW]
blocked_from_sale[RW]
community[RW]
companies[RW]
country[RW]
data_quality[RW]
date_added[RW]
date_changed[RW]
estimated_weight[RW]
extraartists[RW]
format_quantity[RW]
formats[RW]
genres[RW]
identifiers[RW]
images[RW]
labels[RW]
lowest_price[RW]
main_release[RW]
main_release_url[RW]
master[RW]
master_id[RW]
master_url[RW]
most_recent_release[RW]
most_recent_release_url[RW]
notes[RW]
num_for_sale[RW]
released[RW]
released_formatted[RW]
resource_url[RW]
series[RW]
status[RW]
styles[RW]
thumb[RW]
title[RW]
tracklist[RW]
uri[RW]
versions_url[RW]
videos[RW]
year[RW]
Public Class Methods
csv_header()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 49 def self.csv_header %w[ID year artist title].to_csv end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 101 def <=>(other) sort_tuple <=> other.sort_tuple end
artist()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 93 def artist ReleaseArtist.artists_to_s(@artists) end
artist_key()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 97 def artist_key @artists.first.key end
artists=(artists)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 53 def artists=(artists) @artists = artists.map { |a| ReleaseArtist.new(a) } end
cd?()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 89 def cd? @formats.find(&:cd?) != nil end
date_added=(date)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 61 def date_added=(date) @date_added = DateTime.parse(date.to_s) end
date_changed=(date)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 65 def date_changed=(date) @date_changed = DateTime.parse(date.to_s) end
details_to_s()
click to toggle source
# 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:)
click to toggle source
# 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()
click to toggle source
# 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
extraartists=(artists)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 57 def extraartists=(artists) @extraartists = artists.map { |a| ReleaseArtist.new(a) } end
formats=(formats)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 69 def formats=(formats) @formats = formats.map { |f| Format.new(f) } end
link_images(images_dir)
click to toggle source
# 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()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 85 def original_release_year @master&.release_year || release_year end
release_year()
click to toggle source
# 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()
click to toggle source
# 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.update_tags end end
sort_tuple()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 105 def sort_tuple [artist_key, original_release_year || 0, @title] end
summary_to_s()
click to toggle source
# 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()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 109 def to_csv [@id, original_release_year, artist, @title].to_csv end
to_label()
click to toggle source
# 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()
click to toggle source
# File lib/musicbox/catalog/release.rb, line 113 def to_s summary_to_s end
tracklist=(tracklist)
click to toggle source
# File lib/musicbox/catalog/release.rb, line 73 def tracklist=(tracklist) @tracklist = tracklist.map { |t| Track.new(t) } end
tracklist_flattened(tracklist=nil)
click to toggle source
# 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)
click to toggle source
# 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