Class: AlbumCredits::Finder
- Inherits:
-
Object
- Object
- AlbumCredits::Finder
- Includes:
- Display
- Defined in:
- lib/album_credits/finder.rb
Constant Summary
Constants included from Display
Instance Attribute Summary collapse
-
#discogs ⇒ Object
readonly
Returns the value of attribute discogs.
Instance Method Summary collapse
-
#engineers_for_release(release) ⇒ Object
TODO: Look into filtering.
- #find_releases(artist, album) ⇒ Object
-
#initialize(api_key = "vTVvYBauSDUjTGNmVGdjqEavQHRWdkhtWerSqJul") ⇒ Finder
constructor
A new instance of Finder.
- #parse_discogs_id(search_result) ⇒ Object
Methods included from Display
#cp, #default_color, #display_engineer_data, #display_release, #engineer_discog_max, #get_artist_discog, #image_uri_for_release
Constructor Details
#initialize(api_key = "vTVvYBauSDUjTGNmVGdjqEavQHRWdkhtWerSqJul") ⇒ Finder
Returns a new instance of Finder.
8 9 10 |
# File 'lib/album_credits/finder.rb', line 8 def initialize(api_key="vTVvYBauSDUjTGNmVGdjqEavQHRWdkhtWerSqJul") @discogs = Discogs::Wrapper.new("album_credits", user_token: api_key) end |
Instance Attribute Details
#discogs ⇒ Object (readonly)
Returns the value of attribute discogs.
6 7 8 |
# File 'lib/album_credits/finder.rb', line 6 def discogs @discogs end |
Instance Method Details
#engineers_for_release(release) ⇒ Object
TODO: Look into filtering.
58 59 60 |
# File 'lib/album_credits/finder.rb', line 58 def engineers_for_release(release) release.extraartists end |
#find_releases(artist, album) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/album_credits/finder.rb', line 16 def find_releases(artist, album) releases = [] possibilities = discogs.search(album, type: 'release', artist: artist) if possibilities.pagination.items > 0 possibilities.results.each do |found_album| begin release = discogs.get_release(found_album.id) rescue Exception => e debug "Failed to find release id #{found_album.id}: #{e}" next end # Make sure the album is actually in an Accepted state (as per Discogs). if release.status == 'Accepted' releases << release else debug "unacceptable: #{release.title} #{release.status}" end end else debug "no results for #{artist} #{album}" end raise AlbumCredits::NoReleasesFound.new(artist, album) if releases.empty? # Sometimes Discogs returns duplicate releases so # filter out any duplicates based on id. seen = {} uniq_releases = releases.inject([]) do |uniq, rel| unless seen.has_key?(rel.id) seen[rel.id] = 1 uniq << rel end uniq end # Only return with nil release date filter unless it filters out everything. pristine_releases = uniq_releases.reject{|release| release.released.nil?} pristine_releases.size < uniq_releases.size ? pristine_releases : uniq_releases end |
#parse_discogs_id(search_result) ⇒ Object
12 13 14 |
# File 'lib/album_credits/finder.rb', line 12 def parse_discogs_id(search_result) search_result.uri.split('/').last end |