tagomatic 0.0.2
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/.document +5 -0
- data/.gitignore +22 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/ant.xml +7 -0
- data/.idea/compiler.xml +56 -0
- data/.idea/dictionaries/dl.xml +3 -0
- data/.idea/dynamic.xml +3 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +192 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +8 -0
- data/.idea/misc.xml +42 -0
- data/.idea/modules.xml +9 -0
- data/.idea/projectCodeStyle.xml +8 -0
- data/.idea/tagomatic.iml +13 -0
- data/.idea/templateLanguages.xml +3 -0
- data/.idea/uiDesigner.xml +125 -0
- data/.idea/vcs.xml +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +25 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/tagomatic +5 -0
- data/lib/monkey/string.rb +10 -0
- data/lib/tagomatic/format_compiler.rb +44 -0
- data/lib/tagomatic/format_matcher.rb +35 -0
- data/lib/tagomatic/info_updater.rb +62 -0
- data/lib/tagomatic/local_options_matcher.rb +40 -0
- data/lib/tagomatic/logger.rb +20 -0
- data/lib/tagomatic/main.rb +68 -0
- data/lib/tagomatic/mp3info_wrapper.rb +14 -0
- data/lib/tagomatic/object_factory.rb +23 -0
- data/lib/tagomatic/options.rb +21 -0
- data/lib/tagomatic/options_parser.rb +90 -0
- data/lib/tagomatic/scanner.rb +101 -0
- data/lib/tagomatic/system_configuration.rb +64 -0
- data/lib/tagomatic/tagger.rb +190 -0
- data/tagomatic.gemspec +114 -0
- data/test/data/sorted/80s/Peter_Schilling/Fast_alles_konstruiert/01-Fast_alles_konstruiert.mp3 +0 -0
- data/test/data/sorted/80s/Peter_Schilling/Fast_alles_konstruiert/02-Dann_truegt_der_schein.mp3 +0 -0
- data/test/helper.rb +10 -0
- data/test/test_tagomatic.rb +7 -0
- metadata +142 -0
data/.idea/vcs.xml
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Daniel Lukic
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
= tagomatic
|
2
|
+
|
3
|
+
Simple command-line mp3 tagger based on mp3info gem. Supports folder-specific configuration files.
|
4
|
+
|
5
|
+
Another mp3 tagger the world does not need.
|
6
|
+
|
7
|
+
But I needed it. I have a large collection of old mp3 files. From times when tagging was mostly
|
8
|
+
based on the file and folder names. When v2 tags where nowhere close..
|
9
|
+
|
10
|
+
Modes of operation:
|
11
|
+
|
12
|
+
* The tagger will try to guess the tags from the full file path by applying a set of known formats.
|
13
|
+
* The tagger will apply specific tags given on the command-line.
|
14
|
+
* The tagger will match specific formats given on the command-line.
|
15
|
+
* Arbitraty combination of the before-mentioned modes.
|
16
|
+
|
17
|
+
The scanner supports recursive folder handling. Of course.
|
18
|
+
|
19
|
+
Right now v2 tags are the focus.
|
20
|
+
|
21
|
+
It is probably best to call this alpha ware.
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2009 Daniel Lukic. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "tagomatic"
|
8
|
+
gem.summary = %Q{Simple command-line mp3 tagger based on mp3info gem. Supports folder-specific configuration files.}
|
9
|
+
gem.description = File.read('README.rdoc')
|
10
|
+
gem.email = "daniel.lukic@berlinfactor.com"
|
11
|
+
gem.homepage = "http://github.com/DanielLukic/tagomatic"
|
12
|
+
gem.authors = ["Daniel Lukic"]
|
13
|
+
gem.add_dependency "ruby-mp3info", ">= 0"
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "tagomatic #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/tagomatic
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Tagomatic
|
2
|
+
|
3
|
+
class FormatCompiler
|
4
|
+
|
5
|
+
FORMAT_REGEXP_ARTIST = '([^\/]+)'
|
6
|
+
FORMAT_REGEXP_ALBUM = '([^\/]+)'
|
7
|
+
FORMAT_REGEXP_DISC = '([0-9]+)'
|
8
|
+
FORMAT_REGEXP_GENRE = '([^\/]+)'
|
9
|
+
FORMAT_REGEXP_IGNORE = '([^\/]+)'
|
10
|
+
FORMAT_REGEXP_TITLE = '([^\/]+)'
|
11
|
+
FORMAT_REGEXP_TRACKNUM = '([0-9]+)'
|
12
|
+
FORMAT_REGEXP_YEAR = '([0-9]+)'
|
13
|
+
|
14
|
+
def initialize(format_matcher_factory)
|
15
|
+
@format_matcher_factory = format_matcher_factory
|
16
|
+
end
|
17
|
+
|
18
|
+
def compile_format(format)
|
19
|
+
parts = format.split('%')
|
20
|
+
prefix = parts.shift
|
21
|
+
tag_mapping = []
|
22
|
+
regexp = Regexp.escape(prefix)
|
23
|
+
parts.each do |tag_and_tail|
|
24
|
+
tag = tag_and_tail[0, 1]
|
25
|
+
tail = tag_and_tail[1..-1]
|
26
|
+
tag_mapping << tag
|
27
|
+
regexp << FORMAT_REGEXP_ALBUM if tag == Tagomatic::Tagger::FORMAT_ID_ALBUM
|
28
|
+
regexp << FORMAT_REGEXP_ARTIST if tag == Tagomatic::Tagger::FORMAT_ID_ARTIST
|
29
|
+
regexp << FORMAT_REGEXP_DISC if tag == Tagomatic::Tagger::FORMAT_ID_DISC
|
30
|
+
regexp << FORMAT_REGEXP_GENRE if tag == Tagomatic::Tagger::FORMAT_ID_GENRE
|
31
|
+
regexp << FORMAT_REGEXP_IGNORE if tag == Tagomatic::Tagger::FORMAT_ID_IGNORE
|
32
|
+
regexp << FORMAT_REGEXP_TITLE if tag == Tagomatic::Tagger::FORMAT_ID_TITLE
|
33
|
+
regexp << FORMAT_REGEXP_TRACKNUM if tag == Tagomatic::Tagger::FORMAT_ID_TRACKNUM
|
34
|
+
regexp << FORMAT_REGEXP_YEAR if tag == Tagomatic::Tagger::FORMAT_ID_YEAR
|
35
|
+
regexp << Regexp.escape(tail)
|
36
|
+
end
|
37
|
+
|
38
|
+
compiled = Regexp.compile(regexp)
|
39
|
+
@format_matcher_factory.create_format_matcher(compiled, tag_mapping, format)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tagomatic
|
2
|
+
|
3
|
+
class FormatMatcher
|
4
|
+
|
5
|
+
def initialize(compiled_regexp, tag_mapping, original_format)
|
6
|
+
@regexp = compiled_regexp
|
7
|
+
@mapping = tag_mapping
|
8
|
+
@format = original_format
|
9
|
+
end
|
10
|
+
|
11
|
+
def match(file_path)
|
12
|
+
matchdata = @regexp.match(file_path)
|
13
|
+
return nil unless matchdata
|
14
|
+
return nil unless matchdata.captures.size == @mapping.size
|
15
|
+
tags = {}
|
16
|
+
0.upto(@mapping.size) do |index|
|
17
|
+
value = matchdata.captures[index]
|
18
|
+
if value
|
19
|
+
value = value.gsub('_', ' ')
|
20
|
+
parts = value.split(' ')
|
21
|
+
capitalized = parts.map {|p| p.capitalize}
|
22
|
+
value = capitalized.join(' ')
|
23
|
+
end
|
24
|
+
tags[@mapping[index]] = value
|
25
|
+
end
|
26
|
+
tags
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
@format
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Tagomatic
|
2
|
+
|
3
|
+
class InfoUpdater
|
4
|
+
|
5
|
+
def initialize(mp3info)
|
6
|
+
@info = mp3info
|
7
|
+
@updates = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def apply
|
11
|
+
@updates.each { |tag, value| write(tag, value) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def dirty?
|
15
|
+
@updates.each do |tag, value|
|
16
|
+
current_value = read(tag).to_s
|
17
|
+
return true if current_value != value.to_s
|
18
|
+
end
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def album=(value)
|
23
|
+
update :album, value
|
24
|
+
end
|
25
|
+
|
26
|
+
def artist=(value)
|
27
|
+
update :artist, value
|
28
|
+
end
|
29
|
+
|
30
|
+
def genre_s=(value)
|
31
|
+
update :genre_s, value
|
32
|
+
end
|
33
|
+
|
34
|
+
def title=(value)
|
35
|
+
update :title, value
|
36
|
+
end
|
37
|
+
|
38
|
+
def tracknum=(value)
|
39
|
+
update :tracknum, value
|
40
|
+
end
|
41
|
+
|
42
|
+
def year=(value)
|
43
|
+
update :year, value
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def update(tag, value)
|
49
|
+
@updates[tag] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def read(tag)
|
53
|
+
@info.tag2.send(tag)
|
54
|
+
end
|
55
|
+
|
56
|
+
def write(tag, value)
|
57
|
+
@info.tag.send "#{tag}=".to_sym, value
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Tagomatic
|
2
|
+
|
3
|
+
class LocalOptionsMatcher
|
4
|
+
|
5
|
+
def process!(line)
|
6
|
+
@matchdata = LOCAL_OPTIONS_ENTRY_REGEX.match(line)
|
7
|
+
end
|
8
|
+
|
9
|
+
def is_valid_option?
|
10
|
+
@matchdata.captures.size > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_option
|
14
|
+
@matchdata.captures[OPTION_MATCH_GROUP_INDEX]
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_value?
|
18
|
+
@matchdata.captures.size > 2
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_value
|
22
|
+
@matchdata.captures[VALUE_MATCH_GROUP_INDEX]
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_argv
|
26
|
+
argv = []
|
27
|
+
argv << get_option if is_valid_option?
|
28
|
+
argv << get_value if has_value?
|
29
|
+
argv
|
30
|
+
end
|
31
|
+
|
32
|
+
LOCAL_OPTIONS_ENTRY_REGEX = /(--[^ ]+)( (.+))?/
|
33
|
+
|
34
|
+
OPTION_MATCH_GROUP_INDEX = 0
|
35
|
+
|
36
|
+
VALUE_MATCH_GROUP_INDEX = 2
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tagomatic
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def error(message, optional_exception = nil)
|
10
|
+
puts "ERROR: #{message}"
|
11
|
+
$stderr.puts optional_exception.backtrace if optional_exception
|
12
|
+
end
|
13
|
+
|
14
|
+
def verbose(message)
|
15
|
+
puts message if @options[:verbose]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'tagomatic/format_compiler'
|
2
|
+
require 'tagomatic/object_factory'
|
3
|
+
require 'tagomatic/logger'
|
4
|
+
require 'tagomatic/mp3info_wrapper'
|
5
|
+
require 'tagomatic/options'
|
6
|
+
require 'tagomatic/options_parser'
|
7
|
+
require 'tagomatic/scanner'
|
8
|
+
require 'tagomatic/system_configuration'
|
9
|
+
require 'tagomatic/tagger'
|
10
|
+
|
11
|
+
module Tagomatic
|
12
|
+
|
13
|
+
class Main
|
14
|
+
|
15
|
+
def self.run!(*arguments)
|
16
|
+
configuration = Tagomatic::SystemConfiguration.new do
|
17
|
+
register :options => Tagomatic::Options.new
|
18
|
+
register :parser => Tagomatic::OptionsParser.new(get_options)
|
19
|
+
register :local_options_matcher_factory => Tagomatic::ObjectFactory.new
|
20
|
+
register :logger => Tagomatic::Logger.new(get_options)
|
21
|
+
register :scanner => Tagomatic::Scanner.new(get_options, get_parser, get_local_options_matcher_factory, get_logger)
|
22
|
+
register :format_matcher_factory => Tagomatic::ObjectFactory.new
|
23
|
+
register :compiler => Tagomatic::FormatCompiler.new(get_format_matcher_factory)
|
24
|
+
register :mp3info => Tagomatic::Mp3InfoWrapper.new
|
25
|
+
register :info_updater_factory => Tagomatic::ObjectFactory.new
|
26
|
+
register :tagger => Tagomatic::Tagger.new(get_options, get_compiler, get_mp3info, get_info_updater_factory, get_logger)
|
27
|
+
end
|
28
|
+
|
29
|
+
parser = configuration[:parser]
|
30
|
+
parser.parse!(arguments)
|
31
|
+
|
32
|
+
new(configuration).run!
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(configuration)
|
36
|
+
@configuration = configuration
|
37
|
+
end
|
38
|
+
|
39
|
+
def run!
|
40
|
+
options = @configuration[:options]
|
41
|
+
|
42
|
+
show_known_formats_and_exit if options[:list]
|
43
|
+
show_usage_and_exit if options[:files].empty?
|
44
|
+
|
45
|
+
scanner = @configuration[:scanner]
|
46
|
+
tagger = @configuration[:tagger]
|
47
|
+
|
48
|
+
files = options[:files]
|
49
|
+
files.each do |file|
|
50
|
+
scanner.process!(nil, file) do |mp3filepath|
|
51
|
+
tagger.process!(mp3filepath)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def show_usage_and_exit
|
57
|
+
puts @configuration[:parser].show_help
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def show_known_formats_and_exit
|
62
|
+
puts Tagomatic::Tagger::KNOWN_FORMATS
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tagomatic/format_matcher'
|
2
|
+
require 'tagomatic/info_updater'
|
3
|
+
require 'tagomatic/local_options_matcher'
|
4
|
+
|
5
|
+
module Tagomatic
|
6
|
+
|
7
|
+
class ObjectFactory
|
8
|
+
|
9
|
+
def create_local_options_matcher(*arguments)
|
10
|
+
Tagomatic::LocalOptionsMatcher.new(*arguments)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_format_matcher(*arguments)
|
14
|
+
Tagomatic::FormatMatcher.new(*arguments)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_info_updater(*arguments)
|
18
|
+
Tagomatic::InfoUpdater.new(*arguments)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|