taffy 1.3.0 → 1.4.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.
Files changed (7) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/LICENSE +1 -1
  4. data/README.md +5 -1
  5. data/bin/taffy +38 -9
  6. data/taffy.gemspec +5 -5
  7. metadata +13 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 58282fce937d3bff94a00d40c3d8798b0211415f
4
- data.tar.gz: 585d5092e405198779f2ae3876ee93ce6a0e1d54
2
+ SHA256:
3
+ metadata.gz: 7b1c511bd3c2b69dc0a43e2f9ede16732f6712bce3f1cdee40240e2147622189
4
+ data.tar.gz: 78562d02d2ace2e15661d50547cbfb661b5f584257c57650f96f2aabb32c7669
5
5
  SHA512:
6
- metadata.gz: f14622caae83525e8e890932dd1ce446b4530cf03a1d6ae8b4aede000a8368508ef6dcde6e4abbf433fbc5e58c757c25948b7361b0e175f3da6858b9988b7c72
7
- data.tar.gz: 135bb7b972ad6f1516d2ecc2a41be27dba2aaaefd9504b532d0e09fc377aa546b91c61dc6ad8ea708898ce56c793e0453eac72887f986e1b495ff18bd33d3002
6
+ metadata.gz: b227a31fd3b62c419f7501c423057a876ee5d33b17477ea720ab8971effe6dc3491b37eb9bf997af9b1336c754eca157709cb5e580fc2c999e58194b40ae1f2a
7
+ data.tar.gz: 4705920bb9fdeb000f43abb4641ce00772172dc4c18cc36df6bcc1eebf8077340816dd5f6d4f91f732813388a5498de3971596eced429b86bf77321f926e6bb8
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Brandon Mulcahy
1
+ Copyright (c) 2015-2018 Brandon Mulcahy
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -40,6 +40,7 @@ Usage
40
40
  Filename options:
41
41
  --extract SPEC Extract tags from filename
42
42
  --rename SPEC Rename file based on tags
43
+ --rename-fs SPEC Like --rename; see below
43
44
 
44
45
  If no options are given, file tags are printed instead.
45
46
 
@@ -48,6 +49,9 @@ Usage
48
49
  filename, %R leaves letter case intact, while %r downcases
49
50
  the tag. A sequence such as %_t maps special characters in
50
51
  the tag to the given substitute, in this case an underscore.
52
+ --rename remaps all characters that need to be escaped in
53
+ the shell, while --rename-fs remaps only characters that
54
+ are invalid in filenames.
51
55
 
52
56
  Other options:
53
57
  -h, --help Show this message and exit
@@ -65,7 +69,7 @@ Tag a series of files with an artist, album, and year:
65
69
 
66
70
  Tag an audio file, then rename it to "14 - Queen of the Mole People.mp3":
67
71
 
68
- taffy -n 14 -t "Queen of the Mole People" --rename "%n - %T" song.mp3
72
+ taffy -n 14 -t "Queen of the Mole People" --rename-fs "%n - %T" song.mp3
69
73
 
70
74
  Etymology
71
75
  ---------
data/bin/taffy CHANGED
@@ -5,7 +5,7 @@ require 'shellwords'
5
5
 
6
6
  require 'taglib'
7
7
 
8
- VERSION = [1, 3, 0]
8
+ VERSION = [1, 4, 2]
9
9
 
10
10
  FIELDS = [
11
11
  ['l', 'album', String],
@@ -17,8 +17,11 @@ FIELDS = [
17
17
  ['y', 'year', Integer],
18
18
  ]
19
19
 
20
+ RENAME_CHARS = /[ `~!#$%^&*()=[{}\\|;:",<>\/?]|\\]/
21
+ RENAME_FS_CHARS = /[<>:"\/\\|?*]/
22
+
20
23
  actions = []
21
- extract_spec = rename_spec = nil
24
+ extract_spec = rename_spec = special_chars = nil
22
25
  $status = 0
23
26
 
24
27
  options = OptionParser.new do |opts|
@@ -60,6 +63,11 @@ options = OptionParser.new do |opts|
60
63
  end
61
64
  opts.on("--rename SPEC", String, "Rename file based on tags") do |spec|
62
65
  rename_spec = spec
66
+ special_chars = RENAME_CHARS
67
+ end
68
+ opts.on("--rename-fs SPEC", String, "Like --rename; see below") do |spec|
69
+ rename_spec = spec
70
+ special_chars = RENAME_FS_CHARS
63
71
  end
64
72
 
65
73
  opts.separator ""
@@ -70,6 +78,9 @@ options = OptionParser.new do |opts|
70
78
  opts.separator "filename, %R leaves letter case intact, while %r downcases"
71
79
  opts.separator "the tag. A sequence such as %_t maps special characters in"
72
80
  opts.separator "the tag to the given substitute, in this case an underscore."
81
+ opts.separator "--rename remaps all characters that need to be escaped in"
82
+ opts.separator "the shell, while --rename-fs remaps only characters that"
83
+ opts.separator "are invalid in filenames."
73
84
  opts.separator ""
74
85
  opts.separator "Other options:"
75
86
 
@@ -131,7 +142,14 @@ def extract(tag, spec, filename)
131
142
  end
132
143
  end
133
144
 
134
- def rename(tag, spec)
145
+ def strip_special_chars(str, subchar, special_chars)
146
+ # removing single quotes is usually better than remapping them
147
+ str.delete(special_chars == RENAME_CHARS ? "'" : '')
148
+ .gsub(special_chars, subchar).gsub(/(#{subchar})+/, subchar)
149
+ .gsub(/(^#{subchar}|#{subchar}$)/, '') || '_'
150
+ end
151
+
152
+ def rename(tag, spec, special_chars)
135
153
  spec = spec.dup
136
154
 
137
155
  FIELDS.each do |f|
@@ -139,13 +157,25 @@ def rename(tag, spec)
139
157
  tag_string = tag_string.rjust(2, '0') if f[1] == 'track'
140
158
  spec.gsub!(/%(\W|_)?(#{f[0]}|#{f[0].upcase})/) do |match|
141
159
  sub = $2 == f[0] ? tag_string.downcase : tag_string
142
- match.size == 3 ? sub.shellescape.gsub(/\\./, $1) : sub
160
+ strip_special_chars(sub, $1 || '', special_chars)
143
161
  end
144
162
  end
145
163
 
146
164
  spec
147
165
  end
148
166
 
167
+ def safe_save(filename, fileref)
168
+ lowername = filename.downcase
169
+
170
+ if lowername.end_with?('.ogg') or lowername.end_with?('.oga')
171
+ warn("Not saving Ogg Vorbis file: #{filename} - see " +
172
+ "https://github.com/robinst/taglib-ruby/issues/82")
173
+ return false
174
+ else
175
+ return fileref.save
176
+ end
177
+ end
178
+
149
179
  ARGV.each do |filename|
150
180
  TagLib::FileRef.open(filename) do |fileref|
151
181
  if fileref.null?
@@ -156,20 +186,19 @@ ARGV.each do |filename|
156
186
 
157
187
  if extract_spec
158
188
  extract(fileref.tag, extract_spec, filename)
159
- fileref.save
189
+ $status = 2 if not safe_save(filename, fileref)
160
190
  end
161
191
 
162
192
  if actions.empty? and !(extract_spec or rename_spec)
163
193
  print_info(filename, fileref.tag)
164
194
  elsif !actions.empty?
165
195
  actions.each { |action| action.call(fileref.tag) }
166
- fileref.save
196
+ $status = 2 if not safe_save(filename, fileref)
167
197
  end
168
198
 
169
199
  if rename_spec
170
- name = rename(fileref.tag, rename_spec) + File.extname(filename)
171
- name.gsub!('/', '-') # problematic on unix
172
- name.gsub!(':', '') # problematic on windows
200
+ name = rename(fileref.tag, rename_spec, special_chars) +
201
+ File.extname(filename)
173
202
  path = File.join(File.dirname(filename), name)
174
203
  if File.exist?(path)
175
204
  warn("Cannot rename; file exists: #{name}")
data/taffy.gemspec CHANGED
@@ -1,17 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'taffy'
3
- s.version = '1.3.0'
4
- s.date = '2017-07-07'
3
+ s.version = '1.4.2'
4
+ s.date = '2020-03-17'
5
5
  s.summary = 'A command-line audio tagging tool'
6
6
  s.description = "A command-line tool for reading and writing audio \
7
7
  metadata.".squeeze(' ')
8
8
  s.authors = ['Brandon Mulcahy']
9
- s.email = 'brandon@jangler.info'
9
+ s.email = 'brandon@lightcones.net'
10
10
  s.files = `git ls-files`.split
11
- s.homepage = 'https://jangler.info/code/taffy'
11
+ s.homepage = 'https://github.com/jangler/taffy'
12
12
  s.license = 'MIT'
13
13
 
14
14
  s.executables << 'taffy'
15
- s.add_runtime_dependency 'taglib-ruby', '~> 0.7', '>= 0.7.0'
15
+ s.add_runtime_dependency 'taglib-ruby', '~> 1.1', '>= 1.1.0'
16
16
  s.required_ruby_version = '>= 2.0.0'
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mulcahy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -16,36 +16,37 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '1.1'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.7.0
22
+ version: 1.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.7'
29
+ version: '1.1'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.7.0
32
+ version: 1.1.0
33
33
  description: A command-line tool for reading and writing audio metadata.
34
- email: brandon@jangler.info
34
+ email: brandon@lightcones.net
35
35
  executables:
36
36
  - taffy
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
+ - ".gitignore"
40
41
  - LICENSE
41
42
  - README.md
42
43
  - bin/taffy
43
44
  - taffy.gemspec
44
- homepage: https://jangler.info/code/taffy
45
+ homepage: https://github.com/jangler/taffy
45
46
  licenses:
46
47
  - MIT
47
48
  metadata: {}
48
- post_install_message:
49
+ post_install_message:
49
50
  rdoc_options: []
50
51
  require_paths:
51
52
  - lib
@@ -60,9 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  requirements: []
63
- rubyforge_project:
64
- rubygems_version: 2.6.11
65
- signing_key:
64
+ rubygems_version: 3.2.7
65
+ signing_key:
66
66
  specification_version: 4
67
67
  summary: A command-line audio tagging tool
68
68
  test_files: []