unitf-tag 0.1.23 → 0.1.27

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88fd979281b215b41615a9675d426d0dec125ae746b4c824600dfad98da63004
4
- data.tar.gz: 60cb6b8fa88cf88bf915ecc0241b1aac928ceeb845851acb48c0afe6caffaa63
3
+ metadata.gz: 14e1d8e28d9848b67e6bb7d268d1fa8e6218d61c72222c9f46a54cfec761648b
4
+ data.tar.gz: b012aacd324ab95d197f3d4b5bd683157693cb05919908256ad3d317d66f1c29
5
5
  SHA512:
6
- metadata.gz: b591396ce2b828640af59694a96b6e3344e8a2a1112c999f85045f4bf8d8edaf83117f343ea4c881ad58774d2b6b047b0f8235b52703a9281534be1ce542df95
7
- data.tar.gz: abda1347dd22199932558cfc2ea06529e0286c7b6a2fa23c0f63faa2edcb1a0778cb4f7a1c25ad1622e7366f1377700c0dda0f6d9537f4f78e43405e8c44fa27
6
+ metadata.gz: 5600015d8ceb5a8cf60a498a77f430127a130d4371751a0407540084f59cfc5f2a9c1c58d022ef6f65d3f7f5a90375fdab901544c72879d2fa172af6d025dc8f
7
+ data.tar.gz: 040ec01ad18ef917a39b9c36f981df172b48c3ff817c065ab595d8445fa9d1cc15ee12b3224c3446cecdf52a5a42a9e7b24d70f90025e7d8cbd4841339c2a45a
data/.vscode/tasks.json CHANGED
@@ -16,7 +16,15 @@
16
16
  "presentation": {
17
17
  "clear": true
18
18
  },
19
- "command": "bundle exec exe/tag --album FOO --year 2022 test-data"
19
+ "command": "bundle exec ruby bin/test.rb"
20
+ },
21
+ {
22
+ "label": "tag-test",
23
+ "type": "shell",
24
+ "options": {
25
+ "cwd": "${workspaceFolder}",
26
+ },
27
+ "command": "bundle exec ruby exe/tag --auto_tag '/Users/mbaron/music2/Dinosaur Jr/Little Fury Things'"
20
28
  },
21
29
  {
22
30
  "label": "test-project",
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # UnitF::Tag
2
2
 
3
+ ## v0.1.26
4
+ - Completely re-do auto-tagging
5
+
3
6
  ## v0.1.22
4
7
  - Look for covers in current directory and parent directory
data/bin/test.rb CHANGED
@@ -4,23 +4,10 @@ require 'unitf/tag'
4
4
 
5
5
  UnitF::Log.to_console
6
6
 
7
- UnitF::Tag.update('test-data/foo.mp3') do |file|
8
- file.tag.artist = 'bar123'
9
- file.tag.year = 1972
10
- file.tag.album = 'This is the album'
11
- file.tag.title = 'This is the title'
12
- file.tag.track = 99
13
- file.auto_cover!
14
- end
7
+ # file = UnitF::Tag::File.new('/Users/mbaron/music2/BJ/2025/foo/bar/../../bj250321.mp3')
15
8
 
16
- file = UnitF::Tag::File.new('test-data/bar.mp3')
17
- # file.tag
9
+ # puts file.auto_tags
18
10
 
19
- file.update do |f|
20
- f.tag.title = 'Hello world2!'
21
- f.tag.track = 100
22
- end
23
-
24
- file.open do |f|
25
- f.tag.title = 'Hello world9!'
26
- end
11
+ # file.update do |f|
12
+ # f.auto_tag!
13
+ # end
data/exe/tag CHANGED
@@ -54,6 +54,10 @@ targets = OptionParser.new do |opts|
54
54
  actions << :auto_tag
55
55
  end
56
56
 
57
+ opts.on('--auto_tags', 'Auto Tags') do
58
+ actions << :auto_tags
59
+ end
60
+
57
61
  opts.on('-f', '--force', 'Force') do
58
62
  opt[:force] = true
59
63
  end
@@ -109,6 +113,8 @@ files.each do |file|
109
113
  o.auto_cover!
110
114
  when :auto_tag
111
115
  o.auto_tag!
116
+ when :auto_tags
117
+ puts "\tauto_tags: #{o.auto_tags}\n\n"
112
118
  end
113
119
  end
114
120
  end
@@ -0,0 +1,63 @@
1
+ module UnitF
2
+ module Tag
3
+ class AutoTags < Hash
4
+ def initialize(pathname)
5
+ super
6
+
7
+ pathname = Pathname.new(pathname) if pathname.is_a?(String)
8
+ @pathname = pathname.realpath
9
+ @dirname = pathname.realpath.dirname
10
+
11
+ merge!(from_path)
12
+ merge!(from_file)
13
+ end
14
+
15
+ def auto_tag_path
16
+ return @auto_tag_path unless @auto_tag_path.nil?
17
+
18
+ ["#{@dirname}/.autotag", "#{@dirname}/../.autotag"].each do |path|
19
+ return @auto_tag_path = path if ::File.exist?(path)
20
+ end
21
+
22
+ nil
23
+ end
24
+
25
+ def from_path
26
+ tags = {}
27
+
28
+ tags[:title] = ::File.basename(@pathname)
29
+ tags[:track] = tags[:title].match(/^\s*\d+/).to_s.to_i
30
+
31
+ # Specific formatting for dated radio
32
+ if tags[:title].scan(/(\.|_|-)((\d\d\d\d)(\.|-)\d\d(\.|-)\d\d(\w*))\./).any?
33
+ tags[:title] = ::Regexp.last_match[2]
34
+ tags[:year] = ::Regexp.last_match[3].to_i
35
+ else
36
+ tags[:title].gsub!(/\.\w+$/, '')
37
+ tags[:title].gsub!(/^\d*\s*(-|\.)*\s*/, '')
38
+ end
39
+
40
+ path_parts = @dirname.to_s.split('/')
41
+ tags[:artist] = path_parts[-2]
42
+ tags[:album] = tags[:album_artist] = path_parts[-1]
43
+
44
+ tags
45
+ end
46
+
47
+ def from_file
48
+ tags = {}
49
+ return tags unless ::File.exist?(auto_tag_path)
50
+
51
+ ::File.read(auto_tag_path).each_line do |line|
52
+ line.chomp!
53
+ tag, value = line.split(/\s*=\s*/)
54
+ tags[tag.strip.to_sym] = value.strip
55
+ end
56
+
57
+ tags
58
+ rescue StandardError
59
+ {}
60
+ end
61
+ end
62
+ end
63
+ end
@@ -68,10 +68,8 @@ module UnitF
68
68
  ["#{dirname}/cover.jpg", "#{dirname}/../cover.jpg"].each do |path|
69
69
  return ::File.realpath(path) if ::File.exist?(path)
70
70
  end
71
- end
72
71
 
73
- def auto_tag_path
74
- "#{dirname}/.autotag"
72
+ nil
75
73
  end
76
74
 
77
75
  def mp3?
@@ -83,88 +81,31 @@ module UnitF
83
81
  end
84
82
 
85
83
  def cover_available?
86
- cover_path != nil
84
+ !cover_path.nil?
87
85
  end
88
86
 
89
87
  def auto_cover!
90
88
  raise Error, "File is not open #{self.class.name}" if tag.nil?
91
89
 
92
- cover!(cover_path)
90
+ cover!(cover_path) if cover_available?
93
91
  true
94
92
  rescue StandardError => e
95
93
  UnitF::Log.error("Failed to auto-cover file #{e}")
96
94
  false
97
95
  end
98
96
 
99
- def manual_auto_tags
100
- UnitF::Log.info(auto_tag_path)
101
- tags = {}
102
- return {} unless ::File.exist?(auto_tag_path)
103
- ::File.read(auto_tag_path).each_line do |line|
104
- line.chomp!
105
- UnitF::Log.info(line)
106
- tag, value = line.split(/\s*=\s*/)
107
- tags[tag.to_sym] = value
108
- end
109
- tags
110
- rescue StandardError
111
- {}
97
+ def auto_tags
98
+ @auto_tags ||= UnitF::Tag::AutoTags.new(self)
112
99
  end
113
100
 
114
- # def auto_tags
115
- # manual_tags = manual_auto_tags
116
- # tags = {}
117
-
118
- # tags[:title] = ::File.basename(realpath.to_path)
119
- # track = tags[:title].match(/^\s*\d+/).to_s.to_i
120
-
121
- # if tags[:title].scan(/(\.|_|-)(\d\d\d\d(\.|-)\d\d(\.|-)\d\d)/)
122
- # tags[:title] = ::Regexp::last_match
123
- # else
124
- # tags[:title].gsub!(/\.\w+$/, '')
125
- # tags[:title].gsub!(/^\d*\s*(-|\.)*\s*/, '')
126
- # end
127
-
128
- # path_parts = realpath.dirname.to_path.split('/')
129
- # tags[:album] = path_parts[-1]
130
- # tags[:artist] = path_parts[-2]
131
-
132
- # tags.merge(manual_auto_tags)
133
- # end
134
-
135
101
  def auto_tag!
136
102
  UnitF::Log.info("Auto tagging #{self}")
137
-
138
- title = ::File.basename(realpath.to_path)
139
- path_parts = realpath.dirname.to_path.split('/')
140
-
141
- year = nil
142
-
143
- # This must come before gsubbing the title
144
- track = title.match(/^\s*\d+/).to_s.to_i
145
-
146
- # Specific formatting for dated radio
147
- if title.scan(/(\.|_|-)((\d\d\d\d)(\.|-)\d\d(\.|-)\d\d(\w*))\./).any?
148
- title = ::Regexp.last_match[2]
149
- album = path_parts[-1]
150
- year = ::Regexp.last_match[3].to_i
151
- # elsif title.scan(/^(\w\w(\d\d)(\d\d)(\d\d))\./).any?
152
- # title = ::Regexp.last_match[1]
153
- # year = ::Regexp.last_match[1].to_i + 2000
154
- else
155
- title.gsub!(/\.\w+$/, '')
156
- title.gsub!(/^\d*\s*(-|\.)*\s*/, '')
157
- album = path_parts[-1]
158
- end
159
-
160
- artist = path_parts[-2]
161
-
162
- tag.year = year unless year.nil?
163
- tag.album = album
164
- tag.artist = artist
165
- tag.title = title
166
- tag.track = track
167
- self.album_artist = artist
103
+ tag.album = auto_tags[:album]
104
+ tag.artist = auto_tags[:artist]
105
+ tag.title = auto_tags[:title]
106
+ tag.track = auto_tags[:track] if auto_tags.key?(:track)
107
+ tag.year = auto_tags[:year] if auto_tags.key?(:year)
108
+ self.album_artist = auto_tags[:artist]
168
109
  end
169
110
 
170
111
  def properties!(properties)
data/lib/unitf/tag/mp3.rb CHANGED
@@ -23,6 +23,10 @@ module UnitF
23
23
  end
24
24
 
25
25
  def cover!(file_path)
26
+ return unless ::File.exist?(file_path.to_s)
27
+
28
+ delete_cover! if cover?
29
+
26
30
  UnitF::Log.info("Setting cover #{file_path}")
27
31
  apic = TagLib::ID3v2::AttachedPictureFrame.new
28
32
  apic.mime_type = 'image/jpeg'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = '0.1.23'
5
+ VERSION = '0.1.27'
6
6
  end
7
7
  end
data/lib/unitf/tag.rb CHANGED
@@ -6,6 +6,7 @@ require_relative 'tag/file'
6
6
  require_relative 'tag/fileset'
7
7
  require_relative 'tag/flac'
8
8
  require_relative 'tag/mp3'
9
+ require_relative 'tag/auto_tags'
9
10
 
10
11
  require 'unitf/logging'
11
12
 
data/unitf-tag.gemspec CHANGED
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'lib/unitf/tag/version'
4
+ # require 'rbconfig'
5
+
6
+ # taglib_ruby_version = '>= 2.0.0' unless RbConfig::CONFIG['host_os'].match?(/linux/)
7
+ # taglib_ruby_version = '1.1.3' if RbConfig::CONFIG['host_os'].match?(/linux/)
4
8
 
5
9
  Gem::Specification.new do |spec|
6
10
  spec.name = 'unitf-tag'
@@ -27,6 +31,8 @@ Gem::Specification.new do |spec|
27
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
32
  spec.require_paths = ['lib']
29
33
 
30
- spec.add_dependency 'taglib-ruby', '1.1.2'
34
+ spec.add_dependency 'logger'
35
+ spec.add_dependency 'taglib-ruby', '1.1.3'
36
+ # spec.add_dependency 'taglib-ruby', '>= 2.0.0'
31
37
  spec.add_dependency 'unitf-logging'
32
38
  end
metadata CHANGED
@@ -1,29 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitf-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Baron
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-02-02 00:00:00.000000000 Z
10
+ date: 2025-03-27 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: logger
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: taglib-ruby
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - '='
18
31
  - !ruby/object:Gem::Version
19
- version: 1.1.2
32
+ version: 1.1.3
20
33
  type: :runtime
21
34
  prerelease: false
22
35
  version_requirements: !ruby/object:Gem::Requirement
23
36
  requirements:
24
37
  - - '='
25
38
  - !ruby/object:Gem::Version
26
- version: 1.1.2
39
+ version: 1.1.3
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: unitf-logging
29
42
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +74,7 @@ files:
61
74
  - exe/tag
62
75
  - exe/unitf-autotags
63
76
  - lib/unitf/tag.rb
77
+ - lib/unitf/tag/auto_tags.rb
64
78
  - lib/unitf/tag/export/exporter.rb
65
79
  - lib/unitf/tag/file.rb
66
80
  - lib/unitf/tag/fileset.rb
@@ -77,7 +91,6 @@ metadata:
77
91
  homepage_uri: https://github.com/mattbaron/unitf-tag
78
92
  source_code_uri: https://github.com/mattbaron/unitf-tag
79
93
  changelog_uri: https://github.com/mattbaron/unitf-tag/CHANGELOG.md
80
- post_install_message:
81
94
  rdoc_options: []
82
95
  require_paths:
83
96
  - lib
@@ -92,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
105
  - !ruby/object:Gem::Version
93
106
  version: '0'
94
107
  requirements: []
95
- rubygems_version: 3.5.14
96
- signing_key:
108
+ rubygems_version: 3.6.3
97
109
  specification_version: 4
98
110
  summary: Audio File Tagging
99
111
  test_files: []