tagomatic 0.1.5 → 0.1.6
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 +1 -1
- data/lib/tagomatic/format_compiler.rb +6 -2
- data/lib/tagomatic/format_matcher.rb +19 -3
- data/lib/tagomatic/options_parser.rb +28 -18
- data/lib/tagomatic/scanner.rb +1 -1
- data/lib/tagomatic/tags.rb +10 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -19,13 +19,17 @@ module Tagomatic
|
|
19
19
|
tag = tag_and_tail[0, 1]
|
20
20
|
tail = tag_and_tail[1..-1]
|
21
21
|
tag_mapping << tag
|
22
|
-
regexp << FORMAT_REGEXP_ALBUM if tag == FORMAT_ID_ALBUM
|
23
22
|
regexp << FORMAT_REGEXP_ARTIST if tag == FORMAT_ID_ARTIST
|
23
|
+
regexp << FORMAT_REGEXP_ARTIST_AGAIN if tag == FORMAT_ID_ARTIST_AGAIN
|
24
|
+
regexp << FORMAT_REGEXP_ALBUM if tag == FORMAT_ID_ALBUM
|
25
|
+
regexp << FORMAT_REGEXP_ALBUM_AGAIN if tag == FORMAT_ID_ALBUM_AGAIN
|
24
26
|
regexp << FORMAT_REGEXP_DISC if tag == FORMAT_ID_DISC
|
25
27
|
regexp << FORMAT_REGEXP_GENRE if tag == FORMAT_ID_GENRE
|
26
28
|
regexp << FORMAT_REGEXP_IGNORE if tag == FORMAT_ID_IGNORE
|
27
|
-
regexp << FORMAT_REGEXP_TITLE if tag == FORMAT_ID_TITLE
|
28
29
|
regexp << FORMAT_REGEXP_TRACKNUM if tag == FORMAT_ID_TRACKNUM
|
30
|
+
regexp << FORMAT_REGEXP_TITLE if tag == FORMAT_ID_TITLE
|
31
|
+
regexp << FORMAT_REGEXP_WHITESPACE if tag == FORMAT_ID_WHITESPACE
|
32
|
+
regexp << FORMAT_REGEXP_EXTENDED_WHITESPACE if tag == FORMAT_ID_EXTENDED_WHITESPACE
|
29
33
|
regexp << FORMAT_REGEXP_YEAR if tag == FORMAT_ID_YEAR
|
30
34
|
regexp << Regexp.escape(tail)
|
31
35
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'tagomatic/tags'
|
2
|
+
|
1
3
|
module Tagomatic
|
2
4
|
|
3
5
|
class FormatMatcher
|
4
6
|
|
7
|
+
include Tagomatic::Tags
|
8
|
+
|
5
9
|
def initialize(compiled_regexp, tag_mapping, original_format)
|
6
10
|
@regexp = compiled_regexp
|
7
11
|
@mapping = tag_mapping
|
@@ -12,13 +16,14 @@ module Tagomatic
|
|
12
16
|
matchdata = @regexp.match(file_path)
|
13
17
|
return nil unless matchdata
|
14
18
|
return nil unless matchdata.captures.size == @mapping.size
|
15
|
-
tags = {}
|
19
|
+
@tags = {}
|
16
20
|
0.upto(@mapping.size) do |index|
|
17
21
|
value = matchdata.captures[index]
|
18
22
|
value = normalize(value) if value
|
19
|
-
tags[@mapping[index]] = value
|
23
|
+
@tags[@mapping[index]] = value
|
20
24
|
end
|
21
|
-
|
25
|
+
return nil unless valid_constraints?
|
26
|
+
@tags
|
22
27
|
end
|
23
28
|
|
24
29
|
def to_s
|
@@ -34,6 +39,17 @@ module Tagomatic
|
|
34
39
|
capitalized.join(' ')
|
35
40
|
end
|
36
41
|
|
42
|
+
def valid_constraints?
|
43
|
+
valid_double_match_with_same_value?(FORMAT_ID_ARTIST, FORMAT_ID_ARTIST_AGAIN) &&
|
44
|
+
valid_double_match_with_same_value?(FORMAT_ID_ALBUM, FORMAT_ID_ALBUM_AGAIN)
|
45
|
+
end
|
46
|
+
|
47
|
+
def valid_double_match_with_same_value?(base_tag, again_tag)
|
48
|
+
return true unless @tags.has_key?(again_tag)
|
49
|
+
return false unless @tags.has_key?(base_tag)
|
50
|
+
return @tags[base_tag] == @tags[again_tag]
|
51
|
+
end
|
52
|
+
|
37
53
|
end
|
38
54
|
|
39
55
|
end
|
@@ -24,7 +24,7 @@ module Tagomatic
|
|
24
24
|
OptionParser.new do |opts|
|
25
25
|
opts.banner = "Usage: #{$0} [options..] files.."
|
26
26
|
|
27
|
-
opts.separator ""
|
27
|
+
opts.separator " "
|
28
28
|
opts.separator "Specific options:"
|
29
29
|
|
30
30
|
opts.on("-b", "--album [ALBUM]", "Set this album name.") do |album|
|
@@ -49,47 +49,57 @@ module Tagomatic
|
|
49
49
|
@options[:year] = year
|
50
50
|
end
|
51
51
|
|
52
|
+
opts.separator " "
|
53
|
+
opts.separator "Primary options:"
|
54
|
+
|
52
55
|
opts.on("-f", "--format [FORMAT]", "Try applying this format string to determine tags. Multiple occurrences allowed.") do |format|
|
53
|
-
@options[:formats] << format
|
56
|
+
@options[:formats] << format.gsub('|', '/')
|
54
57
|
end
|
55
58
|
|
59
|
+
opts.separator " "
|
60
|
+
|
56
61
|
opts.on("-c", "--[no-]cleantags", "Clean up tags by removing artist and album from title for example.") do |cleantags|
|
57
62
|
@options[:cleantags]= cleantags
|
58
63
|
end
|
59
|
-
opts.on("-k", "--[no-]cleartags", "Clear any existing v1 and v2 tags.") do |cleartags|
|
64
|
+
opts.on("-k", "--[no-]cleartags", "Clear any existing v1 and v2 tags. This is an expensive and destructive operation.") do |cleartags|
|
60
65
|
@options[:cleartags]= cleartags
|
61
66
|
end
|
62
67
|
opts.on("-e", "--[no-]errorstops", "Stop execution if an error occurs.") do |errorstops|
|
63
68
|
@options[:errorstops]= errorstops
|
64
69
|
end
|
65
|
-
opts.on("-s", "--[no-]guess", "Use format guessing.
|
70
|
+
opts.on("-s", "--[no-]guess", "Use format guessing. Used only if no --format matched.") do |guess|
|
66
71
|
@options[:guess] = guess
|
67
72
|
end
|
68
|
-
opts.on("-l", "--[no-]list", "List available formats for guessing.") do |list|
|
69
|
-
@options[:list] = list
|
70
|
-
end
|
71
73
|
opts.on("-r", "--[no-]recurse", "Scan for files recursively.") do |recurse|
|
72
74
|
@options[:recurse] = recurse
|
73
75
|
end
|
74
|
-
opts.on("-w", "--[no-]showtags", "Show the resulting tags.") do |showtags|
|
75
|
-
@options[:showtags] = showtags
|
76
|
-
end
|
77
76
|
opts.on("-u", "--[no-]underscores", "Replace underscores with spaces before processing a file name.") do |underscores|
|
78
77
|
@options[:underscores] = underscores
|
79
78
|
end
|
79
|
+
opts.on("-v", "--[no-]verbose", "Print verbose messages about processing operations.") do |verbose|
|
80
|
+
@options[:verbose] = verbose
|
81
|
+
end
|
82
|
+
opts.on("-w", "--[no-]showtags", "Show the resulting tags.") do |showtags|
|
83
|
+
@options[:showtags] = showtags
|
84
|
+
end
|
80
85
|
|
81
|
-
opts.separator ""
|
82
|
-
opts.separator "
|
86
|
+
opts.separator " "
|
87
|
+
opts.separator "Informational options:"
|
83
88
|
|
84
|
-
opts.on("-
|
85
|
-
|
89
|
+
opts.on("--help-formats", "Show help on writing --format strings.") do
|
90
|
+
puts File.read(File.join(File.dirname($0), '..', 'lib/tagomatic/tags.rb'))
|
91
|
+
exit
|
86
92
|
end
|
87
|
-
opts.
|
88
|
-
|
93
|
+
opts.on("--list-formats", "List built-in formats used for guessing with --guess option.") do |list|
|
94
|
+
@options[:list] = list
|
95
|
+
end
|
96
|
+
opts.on("--version", "Show version information.") do |version|
|
97
|
+
puts File.read(File.join(File.dirname($0), '..', 'VERSION'))
|
89
98
|
exit
|
90
99
|
end
|
91
|
-
|
92
|
-
|
100
|
+
|
101
|
+
opts.on_tail("--help", "Show this message") do
|
102
|
+
puts opts
|
93
103
|
exit
|
94
104
|
end
|
95
105
|
end
|
data/lib/tagomatic/scanner.rb
CHANGED
@@ -16,7 +16,7 @@ module Tagomatic
|
|
16
16
|
@file_path = path_prefix.nil? ? file_or_folder : File.join(path_prefix, file_or_folder)
|
17
17
|
@logger.verbose "processing #{@file_path}"
|
18
18
|
if is_taggable_file?
|
19
|
-
yield @file_path
|
19
|
+
yield File.expand_path(@file_path)
|
20
20
|
elsif is_scannable?
|
21
21
|
enter_scannable_folder(&block)
|
22
22
|
end
|
data/lib/tagomatic/tags.rb
CHANGED
@@ -17,21 +17,29 @@ module Tagomatic
|
|
17
17
|
# --format "%g/%a/%b - encoded by noone - %y/%n - %t.mp3"
|
18
18
|
|
19
19
|
FORMAT_ID_ARTIST = 'a'
|
20
|
+
FORMAT_ID_ARTIST_AGAIN = 'A'
|
20
21
|
FORMAT_ID_ALBUM = 'b'
|
22
|
+
FORMAT_ID_ALBUM_AGAIN = 'B'
|
21
23
|
FORMAT_ID_DISC = 'd'
|
22
24
|
FORMAT_ID_GENRE = 'g'
|
23
25
|
FORMAT_ID_IGNORE = 'i'
|
24
|
-
FORMAT_ID_TITLE = 't'
|
25
26
|
FORMAT_ID_TRACKNUM = 'n'
|
27
|
+
FORMAT_ID_TITLE = 't'
|
28
|
+
FORMAT_ID_WHITESPACE = 's'
|
29
|
+
FORMAT_ID_EXTENDED_WHITESPACE = 'S'
|
26
30
|
FORMAT_ID_YEAR = 'y'
|
27
31
|
|
28
32
|
FORMAT_REGEXP_ARTIST = '([^\/]+)'
|
33
|
+
FORMAT_REGEXP_ARTIST_AGAIN = FORMAT_REGEXP_ARTIST
|
29
34
|
FORMAT_REGEXP_ALBUM = '([^\/]+)'
|
35
|
+
FORMAT_REGEXP_ALBUM_AGAIN = FORMAT_REGEXP_ALBUM
|
30
36
|
FORMAT_REGEXP_DISC = '\s*([0-9]+)\s*'
|
31
37
|
FORMAT_REGEXP_GENRE = '([^\/]+)'
|
32
38
|
FORMAT_REGEXP_IGNORE = '([^\/]+)'
|
33
|
-
FORMAT_REGEXP_TITLE = '([^\/]+)'
|
34
39
|
FORMAT_REGEXP_TRACKNUM = '\s*([0-9]+)\s*'
|
40
|
+
FORMAT_REGEXP_TITLE = '([^\/]+)'
|
41
|
+
FORMAT_REGEXP_WHITESPACE = '\s*'
|
42
|
+
FORMAT_REGEXP_EXTENDED_WHITESPACE = '[\s\-_\.]*'
|
35
43
|
FORMAT_REGEXP_YEAR = '\s*([0-9]+)\s*'
|
36
44
|
|
37
45
|
end
|