isrcs2mb 0.1.0
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/CHANGES +6 -0
- data/LICENSE +25 -0
- data/README +17 -0
- data/Rakefile +83 -0
- data/bin/isrcs2mb +199 -0
- data/lib/isrcs2mb.rb +1 -0
- metadata +99 -0
data/CHANGES
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
isrcs2mb is Copyright (c) 2009-2010 Philipp Wolfer
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
3. Neither the name of the RBrainz project nor the names of the
|
12
|
+
contributors may be used to endorse or promote products derived from
|
13
|
+
this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
16
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
19
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
20
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
21
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
isrcs2mb
|
2
|
+
|
3
|
+
Simple command line tool to submit ISRCs from a CD to MusicBrainz.
|
4
|
+
For usage details run "isrcs2mb --help".
|
5
|
+
|
6
|
+
Requirements:
|
7
|
+
* Ruby
|
8
|
+
* RBrainz and MB-DiscID (http://rbrainz.rubyforge.org)
|
9
|
+
* icedax
|
10
|
+
* HighLine (http://highline.rubyforge.org)
|
11
|
+
* Launchy (optional, http://copiousfreetime.rubyforge.org/launchy/)
|
12
|
+
|
13
|
+
Usage: isrcs2mb [options]
|
14
|
+
-r, --device DEVICE CD device.
|
15
|
+
-u, --username USERNAME MusicBrainz username.
|
16
|
+
-p, --password PASSWORD MusicBrainz password.
|
17
|
+
-h, --help This help message.
|
data/Rakefile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# $Id: Rakefile 316 2010-12-05 20:23:47Z phw $
|
3
|
+
# Copyright (c) 2010, Philipp Wolfer
|
4
|
+
# All rights reserved.
|
5
|
+
# See LICENSE for permissions.
|
6
|
+
|
7
|
+
# Rakefile for isrcs2mb
|
8
|
+
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
|
11
|
+
task :default do
|
12
|
+
puts "Please see 'rake --tasks' for an overview of the available tasks."
|
13
|
+
end
|
14
|
+
|
15
|
+
# Packaging tasks: -------------------------------------------------------
|
16
|
+
|
17
|
+
PKG_NAME = 'isrcs2mb'
|
18
|
+
PKG_VERSION = '0.1.0'
|
19
|
+
PKG_FILES = FileList[
|
20
|
+
"Rakefile", "LICENSE", "README", "CHANGES", "bin/*", "lib/**/*.rb"
|
21
|
+
]
|
22
|
+
PKG_EXTRA_RDOC_FILES = []
|
23
|
+
|
24
|
+
spec = Gem::Specification.new do |spec|
|
25
|
+
spec.platform = Gem::Platform::RUBY
|
26
|
+
spec.summary = 'Simple command line tool to submit ISRCs from a CD to MusicBrainz.'
|
27
|
+
spec.name = PKG_NAME
|
28
|
+
spec.version = PKG_VERSION
|
29
|
+
spec.files = PKG_FILES
|
30
|
+
spec.bindir = 'bin'
|
31
|
+
spec.executables << 'isrcs2mb'
|
32
|
+
spec.add_dependency('rbrainz', '>= 0.5.1')
|
33
|
+
spec.add_dependency('mb-discid', '>= 0.1.4')
|
34
|
+
spec.add_dependency('highline', '>= 1.6.1')
|
35
|
+
spec.add_dependency('launchy', '>= 0.3.5')
|
36
|
+
spec.requirements << 'icedax >= 1.1.10 (for reading ISRCs)'
|
37
|
+
spec.description = <<EOF
|
38
|
+
Simple command line tool to submit ISRCs from a CD to MusicBrainz.
|
39
|
+
For usage details run "isrcs2mb --help".
|
40
|
+
EOF
|
41
|
+
spec.authors = ['Philipp Wolfer']
|
42
|
+
spec.email = 'phw@rubyforge.org'
|
43
|
+
spec.homepage = 'http://rbrainz.rubyforge.org'
|
44
|
+
spec.rubyforge_project = 'rbrainz'
|
45
|
+
spec.has_rdoc = false
|
46
|
+
spec.extra_rdoc_files = PKG_EXTRA_RDOC_FILES
|
47
|
+
end
|
48
|
+
|
49
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
50
|
+
pkg.need_zip = true
|
51
|
+
pkg.need_tar_gz= true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Build the RBrainz gem and install it"
|
55
|
+
task :install => [:test] do
|
56
|
+
sh %{ruby setup.rb}
|
57
|
+
end
|
58
|
+
|
59
|
+
# Other tasks: -----------------------------------------------------------
|
60
|
+
|
61
|
+
def egrep(pattern)
|
62
|
+
Dir['**/*.rb'].each do |fn|
|
63
|
+
count = 0
|
64
|
+
open(fn) do |f|
|
65
|
+
while line = f.gets
|
66
|
+
count += 1
|
67
|
+
if line =~ pattern
|
68
|
+
puts "#{fn}:#{count}:#{line}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Look for TODO and FIXME tags in the code"
|
76
|
+
task :todo do
|
77
|
+
egrep(/#.*(FIXME|TODO)/)
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "Print version information"
|
81
|
+
task :version do
|
82
|
+
puts "%s %s" % [PKG_NAME, PKG_VERSION]
|
83
|
+
end
|
data/bin/isrcs2mb
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
# $Id: isrcs2mb 316 2010-12-05 20:23:47Z phw $
|
5
|
+
#
|
6
|
+
# Simple command line tool to submit ISRCs from a CD to MusicBrainz.
|
7
|
+
# For usage details run "ruby isrcs2mb --help".
|
8
|
+
#
|
9
|
+
# Requirements:
|
10
|
+
# * Ruby
|
11
|
+
# * RBrainz and MB-DiscID (http://rbrainz.rubyforge.org)
|
12
|
+
# * icedax
|
13
|
+
# * HighLine (http://highline.rubyforge.org)
|
14
|
+
# * Launchy (optional, http://copiousfreetime.rubyforge.org/launchy/)
|
15
|
+
#
|
16
|
+
# Copyright (C) 2009-2010 Philipp Wolfer <ph.wolfer@googlemail.com>
|
17
|
+
#
|
18
|
+
# Redistribution and use in source and binary forms, with or without
|
19
|
+
# modification, are permitted provided that the following conditions
|
20
|
+
# are met:
|
21
|
+
# 1. Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
24
|
+
# notice, this list of conditions and the following disclaimer in the
|
25
|
+
# documentation and/or other materials provided with the distribution.
|
26
|
+
# 3. Neither the name of the RBrainz project nor the names of the
|
27
|
+
# contributors may be used to endorse or promote products derived from
|
28
|
+
# this software without specific prior written permission.
|
29
|
+
#
|
30
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
31
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
32
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
33
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
34
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
35
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
36
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
37
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
38
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
39
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
40
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
41
|
+
|
42
|
+
require 'rbrainz'
|
43
|
+
require 'mb-discid'
|
44
|
+
require 'optparse'
|
45
|
+
require 'highline/import'
|
46
|
+
begin
|
47
|
+
require 'rubygems'
|
48
|
+
require 'launchy'
|
49
|
+
rescue LoadError
|
50
|
+
Launchy = nil
|
51
|
+
end
|
52
|
+
include MusicBrainz
|
53
|
+
|
54
|
+
ICEDAX = (`which icedax`).strip
|
55
|
+
ISRC_COMMAND = "%s -device %s --info-only --no-infofile -v trackid 2>&1"
|
56
|
+
|
57
|
+
def read_isrcs(device)
|
58
|
+
isrcs = []
|
59
|
+
IO.popen(ISRC_COMMAND % [ICEDAX, device]) do |io|
|
60
|
+
io.each_line do |line|
|
61
|
+
if line =~ /T:\s+(\d+)\s+ISRC:\s+([A-Z]{2}-?\w{3}-?\d{2}-?\d{5})$/
|
62
|
+
isrcs[$1.to_i - 1] = Model::ISRC.parse($2)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return isrcs
|
67
|
+
end
|
68
|
+
|
69
|
+
HighLine.track_eof = false
|
70
|
+
def get_choice(release)
|
71
|
+
Proc.new { release }
|
72
|
+
end
|
73
|
+
|
74
|
+
def submit_release_question(disc)
|
75
|
+
if Launchy
|
76
|
+
if agree("Do you want to submit this release to MusicBrainz?")
|
77
|
+
Launchy.open disc.submission_url
|
78
|
+
end
|
79
|
+
else
|
80
|
+
say "Use the following URL to submit the release to MusicBrainz:\n%s" % disc.submission_url
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
device = DiscID.default_device
|
85
|
+
username = ''
|
86
|
+
password = ''
|
87
|
+
|
88
|
+
# Read the command line parameters
|
89
|
+
opts = OptionParser.new do |o|
|
90
|
+
o.banner = "Usage: isrcs2mb [options]"
|
91
|
+
o.on( "-r", "--device DEVICE", "CD device." ) do |r|
|
92
|
+
device = r
|
93
|
+
end
|
94
|
+
o.on( "-u", "--username USERNAME", "MusicBrainz username." ) do |u|
|
95
|
+
username = u
|
96
|
+
end
|
97
|
+
o.on( "-p", "--password PASSWORD", "MusicBrainz password." ) do |p|
|
98
|
+
password = p
|
99
|
+
end
|
100
|
+
o.on("-h", "--help", "This help message." ) do
|
101
|
+
puts o
|
102
|
+
exit
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
opts.parse!(ARGV)
|
107
|
+
|
108
|
+
if ICEDAX.empty?
|
109
|
+
say "icedax not found. Please make sure that you have installed icedax."
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
|
113
|
+
# Read the disc ID
|
114
|
+
begin
|
115
|
+
disc = MusicBrainz::DiscID.new
|
116
|
+
disc.read(device)
|
117
|
+
say "Disc ID: %s" % disc.id
|
118
|
+
rescue Exception => e
|
119
|
+
say "Can not read disc in %s" % device
|
120
|
+
exit 1
|
121
|
+
end
|
122
|
+
|
123
|
+
say "Reading ISRCs from %s... " % device
|
124
|
+
isrcs = read_isrcs(device)
|
125
|
+
say "%d ISRCs found." % isrcs.size
|
126
|
+
|
127
|
+
if isrcs.size == 0
|
128
|
+
say "No ISRCs found, exiting."
|
129
|
+
exit 1
|
130
|
+
end
|
131
|
+
|
132
|
+
# Ask for user credentials
|
133
|
+
if username.empty?
|
134
|
+
username = ask("Username: ") do |q|
|
135
|
+
q.validate = lambda { |a| not a.empty? }
|
136
|
+
q.responses[:not_valid] = "Please enter a username."
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
if password.empty?
|
141
|
+
password = ask("Password: ") do |q|
|
142
|
+
q.echo = "*"
|
143
|
+
q.validate = lambda { |a| not a.empty? }
|
144
|
+
q.responses[:not_valid] = "Please enter a password."
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Set the authentication for the webservice.
|
149
|
+
ws = Webservice::Webservice.new(
|
150
|
+
:host => 'musicbrainz.org',
|
151
|
+
:username => username,
|
152
|
+
:password => password
|
153
|
+
)
|
154
|
+
|
155
|
+
# Create a new Query object which will provide
|
156
|
+
# us an interface to the MusicBrainz web service.
|
157
|
+
query = Webservice::Query.new(ws, :client_id => 'RBrainz ISRC submission ' + RBRAINZ_VERSION)
|
158
|
+
releases = query.get_releases(:discid => disc)
|
159
|
+
|
160
|
+
if releases.size == 0
|
161
|
+
say "\nNo release found. "
|
162
|
+
submit_release_question(disc)
|
163
|
+
exit 1
|
164
|
+
end
|
165
|
+
|
166
|
+
# Let the user select one release
|
167
|
+
release = choose do |menu|
|
168
|
+
menu.header = "\nSelect release"
|
169
|
+
for i in 0...releases.size do
|
170
|
+
release = releases[i].entity
|
171
|
+
text = "'%s' by '%s' (%s)" % [release, release.artist, release.id.uuid]
|
172
|
+
menu.choice(text, &get_choice(release))
|
173
|
+
end
|
174
|
+
menu.choice("None of the above") do
|
175
|
+
say "\nNo release found. "
|
176
|
+
submit_release_question(disc)
|
177
|
+
exit 1
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Create a mapping between track IDs and ISRCs
|
182
|
+
track_isrc_map = []
|
183
|
+
for i in 0...release.tracks.size do
|
184
|
+
track = release.tracks[i]
|
185
|
+
isrc = isrcs[i]
|
186
|
+
track_isrc_map << [track.id.uuid, isrc.to_str] unless isrc.nil?
|
187
|
+
end
|
188
|
+
|
189
|
+
# Submit the ISRCs for some tracks.
|
190
|
+
say "Submitting ISRCs for %d tracks to MusicBrainz... " % track_isrc_map.size
|
191
|
+
begin
|
192
|
+
query.submit_isrcs(track_isrc_map)
|
193
|
+
rescue Webservice::AuthenticationError => e
|
194
|
+
say "failed."
|
195
|
+
say "Wrong username or password."
|
196
|
+
exit 1
|
197
|
+
end
|
198
|
+
say "done."
|
199
|
+
exit
|
data/lib/isrcs2mb.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Dummy file for gems.
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isrcs2mb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philipp Wolfer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-12-05 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rbrainz
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.5.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mb-discid
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: highline
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: launchy
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.3.5
|
54
|
+
version:
|
55
|
+
description: " Simple command line tool to submit ISRCs from a CD to MusicBrainz.\n For usage details run \"isrcs2mb --help\".\n"
|
56
|
+
email: phw@rubyforge.org
|
57
|
+
executables:
|
58
|
+
- isrcs2mb
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- Rakefile
|
65
|
+
- LICENSE
|
66
|
+
- README
|
67
|
+
- CHANGES
|
68
|
+
- bin/isrcs2mb
|
69
|
+
- lib/isrcs2mb.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://rbrainz.rubyforge.org
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
requirements:
|
92
|
+
- icedax >= 1.1.10 (for reading ISRCs)
|
93
|
+
rubyforge_project: rbrainz
|
94
|
+
rubygems_version: 1.3.5
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Simple command line tool to submit ISRCs from a CD to MusicBrainz.
|
98
|
+
test_files: []
|
99
|
+
|