album_credits 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/album_credits.gemspec +2 -2
- data/bin/album_credits +12 -9
- data/lib/album_credits/display.rb +10 -2
- data/lib/album_credits/exceptions.rb +11 -0
- data/lib/album_credits/finder.rb +41 -15
- data/lib/album_credits/version.rb +1 -1
- data/lib/album_credits.rb +2 -2
- metadata +8 -7
data/album_credits.gemspec
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
$:.
|
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
|
3
3
|
require "album_credits/version"
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |s|
|
|
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
20
20
|
s.require_paths = ["lib"]
|
|
21
21
|
|
|
22
|
-
s.add_dependency "ruby-debug"
|
|
23
22
|
s.add_dependency "bassnode-discogs"
|
|
23
|
+
s.add_development_dependency "ruby-debug"
|
|
24
24
|
end
|
data/bin/album_credits
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
3
|
|
|
3
|
-
# TEMP
|
|
4
|
-
require 'rubygems'
|
|
5
|
-
require 'bundler'
|
|
6
|
-
require 'ruby-debug'
|
|
7
4
|
require 'album_credits'
|
|
8
5
|
|
|
6
|
+
# TODO Shove this all in a CLI class or some such.
|
|
9
7
|
artist = ARGV[0]
|
|
10
8
|
album = ARGV[1]
|
|
11
9
|
year = ARGV[2]
|
|
12
10
|
ac = AlbumCredits::Finder.new
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
begin
|
|
13
|
+
releases = ac.find_releases(artist, album, year)
|
|
14
|
+
rescue Exception => e
|
|
15
|
+
puts e.message
|
|
16
|
+
exit
|
|
17
|
+
end
|
|
16
18
|
puts "Found #{releases.size} releases"
|
|
17
19
|
|
|
18
20
|
sorted_releases = releases.inject([]) do |rel_array, release|
|
|
@@ -27,6 +29,7 @@ raise "No engineering data though :/" if sorted_releases.empty?
|
|
|
27
29
|
best_guess = sorted_releases.shift
|
|
28
30
|
ac.display_release(best_guess.first, best_guess.last, :color => :green, :show_discography => true)
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
# sorted_releases.each do |release, engineers|
|
|
34
|
+
# ac.display_release(release, engineers)
|
|
35
|
+
# end
|
|
@@ -16,6 +16,12 @@ module AlbumCredits
|
|
|
16
16
|
@default_color = :white
|
|
17
17
|
attr_accessor :default_color
|
|
18
18
|
|
|
19
|
+
# Prints the text in color
|
|
20
|
+
#
|
|
21
|
+
# @param [String] the text to print
|
|
22
|
+
# @param [Hash] opts
|
|
23
|
+
# @options opts [Boolean] :bold
|
|
24
|
+
# @options opts [Symbol] :color (default is .default_color)
|
|
19
25
|
def cp(text, opts={})
|
|
20
26
|
embolden = opts[:bold] ? COLORS[:bold] : ''
|
|
21
27
|
color = opts[:color] || @default_color
|
|
@@ -53,14 +59,16 @@ module AlbumCredits
|
|
|
53
59
|
cp "Engineers:", :color => :yellow
|
|
54
60
|
engineers.each do |engineer|
|
|
55
61
|
next if displayed.include? engineer.name
|
|
56
|
-
cp "#{engineer.role} #{engineer.name}", :bold => true
|
|
62
|
+
cp "#{engineer.role} #{engineer.name}", :bold => true, :color => :red
|
|
57
63
|
|
|
58
64
|
# Print the engineer's discography
|
|
59
65
|
if show_discography && !(artist = discogs.get_artist(CGI.escape(engineer.name))).nil?
|
|
60
66
|
aka = artist.aliases || []
|
|
61
67
|
aka << artist.namevariations || []
|
|
68
|
+
|
|
62
69
|
cp "AKA: #{aka.flatten.uniq.sort.join(', ')}"
|
|
63
|
-
cp "#{artist.releases.size} releases in discography"
|
|
70
|
+
cp "#{artist.releases.size} releases in discography", :color => :yellow
|
|
71
|
+
|
|
64
72
|
# Don't show discog for assistants
|
|
65
73
|
unless engineer.role =~ /assisted|assistant|additional/i
|
|
66
74
|
artist.releases.group_by{ |disk| disk.artist }.sort_by{ |artist, albums| artist }.each do |artist, albums|
|
data/lib/album_credits/finder.rb
CHANGED
|
@@ -13,35 +13,53 @@ module AlbumCredits
|
|
|
13
13
|
search_result.uri.split('/').last
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
# @param [String] the main string to search for
|
|
17
|
+
# @param [Hash,Optional] params
|
|
18
|
+
# @option params [String] :format CD, HDCD, vinyl, etc.
|
|
19
|
+
# @option params [String] :artist
|
|
20
|
+
# @option params [Fixnum] :year
|
|
21
|
+
def search(target, params={})
|
|
22
|
+
sections = []
|
|
23
|
+
params.each_pair do |key, val|
|
|
24
|
+
sections << "#{key}:#{val}" if val
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
search_string = "#{target} AND " << sections.join(" AND ")
|
|
28
|
+
debug "Searching for #{CGI.escape(search_string)}"
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
discogs.search(CGI.escape(search_string), :type => 'releases')
|
|
32
|
+
rescue Discogs::UnknownResource => e
|
|
33
|
+
debug "Nothing found for #{search_string}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
16
37
|
def find_releases(artist, album, year=nil)
|
|
38
|
+
|
|
17
39
|
releases = []
|
|
40
|
+
|
|
18
41
|
[nil, 'CD', 'HDCD', 'vinyl'].each do |format|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rescue Discogs::UnknownResource => e
|
|
24
|
-
puts "Not found: #{e}"
|
|
25
|
-
next
|
|
26
|
-
end
|
|
27
|
-
if possibilities.searchresults.size > 0
|
|
42
|
+
|
|
43
|
+
possibilities = search(album, :artist => artist, :year => year, :format => format)
|
|
44
|
+
|
|
45
|
+
if possibilities && possibilities.searchresults.size > 0
|
|
28
46
|
possibilities.searchresults.each do |found_album|
|
|
29
|
-
# puts "trying #{found_album.inspect}"
|
|
30
47
|
release = discogs.get_release(parse_discogs_id(found_album))
|
|
31
48
|
# Make sure the album is actually what we think it is and that it
|
|
32
49
|
# is in an Accepted state (as per Discogs).
|
|
33
50
|
if release.title =~ /#{album}/i && release.status == 'Accepted'
|
|
34
51
|
releases << release
|
|
52
|
+
else
|
|
53
|
+
debug "unacceptable: #{release.title} #{release.status}"
|
|
35
54
|
end
|
|
36
55
|
end
|
|
37
56
|
else
|
|
38
|
-
|
|
57
|
+
debug "no results for #{artist} #{album} #{year} #{format}"
|
|
39
58
|
end
|
|
40
|
-
end
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
|
|
61
|
+
raise AlbumCredits::NoReleasesFound.new(artist, album, year) if releases.empty?
|
|
62
|
+
end
|
|
45
63
|
|
|
46
64
|
# Sometimes Discogs returns duplicate releases so
|
|
47
65
|
# filter out any duplicates based on id.
|
|
@@ -69,5 +87,13 @@ module AlbumCredits
|
|
|
69
87
|
discogs.get_artist(CGI.escape(artist)) rescue []
|
|
70
88
|
end
|
|
71
89
|
|
|
90
|
+
private
|
|
91
|
+
def debug(txt)
|
|
92
|
+
puts txt if debug?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def debug?
|
|
96
|
+
ENV['DEBUG'].to_i == 1
|
|
97
|
+
end
|
|
72
98
|
end
|
|
73
99
|
end
|
data/lib/album_credits.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'cgi'
|
|
3
3
|
require 'discogs'
|
|
4
|
+
require 'album_credits/exceptions'
|
|
4
5
|
require 'album_credits/core_ext'
|
|
5
6
|
require 'album_credits/display'
|
|
6
7
|
require 'album_credits/finder'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
end
|
|
9
|
+
begin; require 'ruby-debug'; rescue LoadError; end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: album_credits
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.0.3
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- bassnode
|
|
@@ -15,11 +15,11 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-04-
|
|
18
|
+
date: 2011-04-17 00:00:00 -07:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
22
|
-
name:
|
|
22
|
+
name: bassnode-discogs
|
|
23
23
|
prerelease: false
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
@@ -33,7 +33,7 @@ dependencies:
|
|
|
33
33
|
type: :runtime
|
|
34
34
|
version_requirements: *id001
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
|
-
name:
|
|
36
|
+
name: ruby-debug
|
|
37
37
|
prerelease: false
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
@@ -44,7 +44,7 @@ dependencies:
|
|
|
44
44
|
segments:
|
|
45
45
|
- 0
|
|
46
46
|
version: "0"
|
|
47
|
-
type: :
|
|
47
|
+
type: :development
|
|
48
48
|
version_requirements: *id002
|
|
49
49
|
description: Searches databases for a given artist + album combination and returns recording engineering information.
|
|
50
50
|
email:
|
|
@@ -66,6 +66,7 @@ files:
|
|
|
66
66
|
- lib/album_credits.rb
|
|
67
67
|
- lib/album_credits/core_ext.rb
|
|
68
68
|
- lib/album_credits/display.rb
|
|
69
|
+
- lib/album_credits/exceptions.rb
|
|
69
70
|
- lib/album_credits/finder.rb
|
|
70
71
|
- lib/album_credits/version.rb
|
|
71
72
|
has_rdoc: true
|