tagomatic 0.1.6 → 0.1.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -6,8 +6,9 @@ module Tagomatic
6
6
 
7
7
  include Tagomatic::Tags
8
8
 
9
- def initialize(format_matcher_factory)
9
+ def initialize(format_matcher_factory, logger)
10
10
  @format_matcher_factory = format_matcher_factory
11
+ @logger = logger
11
12
  end
12
13
 
13
14
  def compile_format(format)
@@ -31,11 +32,15 @@ module Tagomatic
31
32
  regexp << FORMAT_REGEXP_WHITESPACE if tag == FORMAT_ID_WHITESPACE
32
33
  regexp << FORMAT_REGEXP_EXTENDED_WHITESPACE if tag == FORMAT_ID_EXTENDED_WHITESPACE
33
34
  regexp << FORMAT_REGEXP_YEAR if tag == FORMAT_ID_YEAR
35
+ regexp << FORMAT_REGEXP_SURROUNDED_YEAR if tag == FORMAT_ID_SURROUNDED_YEAR
34
36
  regexp << Regexp.escape(tail)
35
37
  end
36
38
 
37
39
  compiled = Regexp.compile(regexp, Regexp::IGNORECASE)
38
40
  @format_matcher_factory.create_format_matcher(compiled, tag_mapping, format)
41
+ rescue
42
+ @logger.error "failed compiling #{format}", $!
43
+ raise $!
39
44
  end
40
45
 
41
46
  end
@@ -22,6 +22,7 @@ module Tagomatic
22
22
  value = normalize(value) if value
23
23
  @tags[@mapping[index]] = value
24
24
  end
25
+ @tags[FORMAT_ID_YEAR] ||= @tags[FORMAT_ID_SURROUNDED_YEAR]
25
26
  return nil unless valid_constraints?
26
27
  @tags
27
28
  end
@@ -2,43 +2,55 @@ module Tagomatic
2
2
 
3
3
  module KnownFormats
4
4
 
5
- KNOWN_FORMATS = [
6
- "%g/%a/%b/Disc%d/%n-%t.mp3",
7
- "%g/%a/%b/Disc%d/%n.%t.mp3",
8
- "%g/%a/%b/Disc%d/%n%t.mp3",
9
- "%g/%a/%b/Disc%d/%t.mp3",
10
- "%g/%a/%b/cd%d/%n-%t.mp3",
11
- "%g/%a/%b/cd%d/%n.%t.mp3",
12
- "%g/%a/%b/cd%d/%n%t.mp3",
13
- "%g/%a/%b/cd%d/%t.mp3",
14
-
15
- "%g/%a/%b[%y]/%a-%b-%n-%t.mp3",
16
- "%g/%a/%b[%y]/%n-%t.mp3",
17
- "%g/%a/%b[%y]/%n.%t.mp3",
18
- "%g/%a/%b[%y]/%n%t.mp3",
19
-
20
- "%g/%a/%b(%y)/%a-%b-%n-%t.mp3",
21
- "%g/%a/%b(%y)/%n-%t.mp3",
22
- "%g/%a/%b(%y)/%n.%t.mp3",
23
- "%g/%a/%b(%y)/%n%t.mp3",
24
-
25
- "%g/%a/(%y)%b/%a-%b-%n-%t.mp3",
26
- "%g/%a/(%y)%b/%n-%t.mp3",
27
- "%g/%a/(%y)%b/%n.%t.mp3",
28
- "%g/%a/(%y)%b/%n%t.mp3",
29
-
30
- "%g/%a/%y - %b/%a-%b-%n-%t.mp3",
31
- "%g/%a/%y - %b/%n-%t.mp3",
32
- "%g/%a/%y - %b/%n.%t.mp3",
33
- "%g/%a/%y - %b/%n%t.mp3",
34
-
35
- "%g/%a/%b/%a-%b-%n-%t.mp3",
36
- "%g/%a/%b/%n-%t.mp3",
37
- "%g/%a/%b/%n.%t.mp3",
38
- "%g/%a/%b/%n%t.mp3",
39
-
40
- "%g/%a/%b/%t.mp3",
41
- ]
5
+ PREFIXES = [
6
+ "%g/%a/%b-%y",
7
+ "%g/%a/%b %Y",
8
+ "%g/%a/%y-%b",
9
+ "%g/%a/%Y %b",
10
+ "%g/%a/%b",
11
+ ]
12
+
13
+ INFIXES = [
14
+ "[disc%d]/",
15
+ "[disk%d]/",
16
+ "[cd%d]/",
17
+ "(disc%d)/",
18
+ "(disk%d)/",
19
+ "(cd%d)/",
20
+ " disc%d/",
21
+ " disk%d/",
22
+ " cd%d/",
23
+ "/disc%d/",
24
+ "/disk%d/",
25
+ "/cd%d/",
26
+ "/",
27
+ ]
28
+
29
+ SUFFIXES = [
30
+ "%A-%B-%n-%t.mp3",
31
+ "%B-%n-%t.mp3",
32
+ "%A-%n-%t.mp3",
33
+ "%n-%A-%t.mp3",
34
+ "%n-%B-%t.mp3",
35
+ "%n-%t.mp3",
36
+ "%n.%t.mp3",
37
+ "%n%t.mp3",
38
+ "%t.mp3",
39
+ ]
40
+
41
+ def self.inflate_formats
42
+ formats = []
43
+ PREFIXES.each do |p|
44
+ INFIXES.each do |i|
45
+ SUFFIXES.each do |s|
46
+ formats << (p + i + s)
47
+ end
48
+ end
49
+ end
50
+ formats
51
+ end
52
+
53
+ KNOWN_FORMATS = inflate_formats
42
54
 
43
55
  end
44
56
 
@@ -20,7 +20,7 @@ module Tagomatic
20
20
  register :logger => Tagomatic::Logger.new(get_options)
21
21
  register :scanner => Tagomatic::Scanner.new(get_options, get_parser, get_local_options_matcher_factory, get_logger)
22
22
  register :format_matcher_factory => Tagomatic::ObjectFactory.new
23
- register :compiler => Tagomatic::FormatCompiler.new(get_format_matcher_factory)
23
+ register :compiler => Tagomatic::FormatCompiler.new(get_format_matcher_factory, get_logger)
24
24
  register :mp3info => Tagomatic::Mp3InfoWrapper.new
25
25
  register :info_updater_factory => Tagomatic::ObjectFactory.new
26
26
  register :tagger => Tagomatic::Tagger.new(get_options, get_compiler, get_mp3info, get_info_updater_factory, get_logger)
@@ -39,7 +39,6 @@ module Tagomatic
39
39
  def run!
40
40
  options = @configuration[:options]
41
41
 
42
- show_known_formats_and_exit if options[:list]
43
42
  show_usage_and_exit if options[:files].empty?
44
43
 
45
44
  scanner = @configuration[:scanner]
@@ -58,11 +57,6 @@ module Tagomatic
58
57
  exit 1
59
58
  end
60
59
 
61
- def show_known_formats_and_exit
62
- puts Tagomatic::Tagger::KNOWN_FORMATS
63
- exit 1
64
- end
65
-
66
60
  end
67
61
 
68
62
  end
@@ -88,19 +88,20 @@ module Tagomatic
88
88
 
89
89
  opts.on("--help-formats", "Show help on writing --format strings.") do
90
90
  puts File.read(File.join(File.dirname($0), '..', 'lib/tagomatic/tags.rb'))
91
- exit
91
+ exit 1
92
92
  end
93
93
  opts.on("--list-formats", "List built-in formats used for guessing with --guess option.") do |list|
94
- @options[:list] = list
94
+ puts Tagomatic::Tagger::KNOWN_FORMATS
95
+ exit 1
95
96
  end
96
97
  opts.on("--version", "Show version information.") do |version|
97
98
  puts File.read(File.join(File.dirname($0), '..', 'VERSION'))
98
- exit
99
+ exit 1
99
100
  end
100
101
 
101
102
  opts.on_tail("--help", "Show this message") do
102
103
  puts opts
103
- exit
104
+ exit 1
104
105
  end
105
106
  end
106
107
  end
@@ -28,6 +28,7 @@ module Tagomatic
28
28
  FORMAT_ID_WHITESPACE = 's'
29
29
  FORMAT_ID_EXTENDED_WHITESPACE = 'S'
30
30
  FORMAT_ID_YEAR = 'y'
31
+ FORMAT_ID_SURROUNDED_YEAR = 'Y'
31
32
 
32
33
  FORMAT_REGEXP_ARTIST = '([^\/]+)'
33
34
  FORMAT_REGEXP_ARTIST_AGAIN = FORMAT_REGEXP_ARTIST
@@ -36,11 +37,12 @@ module Tagomatic
36
37
  FORMAT_REGEXP_DISC = '\s*([0-9]+)\s*'
37
38
  FORMAT_REGEXP_GENRE = '([^\/]+)'
38
39
  FORMAT_REGEXP_IGNORE = '([^\/]+)'
39
- FORMAT_REGEXP_TRACKNUM = '\s*([0-9]+)\s*'
40
+ FORMAT_REGEXP_TRACKNUM = '\s*\[?([0-9]+)\]?\s*'
40
41
  FORMAT_REGEXP_TITLE = '([^\/]+)'
41
42
  FORMAT_REGEXP_WHITESPACE = '\s*'
42
43
  FORMAT_REGEXP_EXTENDED_WHITESPACE = '[\s\-_\.]*'
43
44
  FORMAT_REGEXP_YEAR = '\s*([0-9]+)\s*'
45
+ FORMAT_REGEXP_SURROUNDED_YEAR = '\s*[\(\[]([0-9]+)[\)\]]\s*'
44
46
 
45
47
  end
46
48
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lukic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-03 00:00:00 +01:00
12
+ date: 2009-11-04 00:00:00 +01:00
13
13
  default_executable: tagomatic
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency