unitf-tag 0.1.27 → 0.2.0

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: 14e1d8e28d9848b67e6bb7d268d1fa8e6218d61c72222c9f46a54cfec761648b
4
- data.tar.gz: b012aacd324ab95d197f3d4b5bd683157693cb05919908256ad3d317d66f1c29
3
+ metadata.gz: 0e8a3abd8e593009ee730ed4ee98c85f9f0b5665cdccf7ac1ea68b0f29e793a6
4
+ data.tar.gz: 2b62f8700524ba32f9961b14c129869a98b4e0fbf304c05173f9e059820d8bb3
5
5
  SHA512:
6
- metadata.gz: 5600015d8ceb5a8cf60a498a77f430127a130d4371751a0407540084f59cfc5f2a9c1c58d022ef6f65d3f7f5a90375fdab901544c72879d2fa172af6d025dc8f
7
- data.tar.gz: 040ec01ad18ef917a39b9c36f981df172b48c3ff817c065ab595d8445fa9d1cc15ee12b3224c3446cecdf52a5a42a9e7b24d70f90025e7d8cbd4841339c2a45a
6
+ metadata.gz: d5a1dd21d9cddb72642a99e8d0f1274f6e95a3fc76e80d9bb71838c6addc201814ac3dd0ff1d38482af6464ab37eddd5cd643d70240bf7fdf5fba80866d9c156
7
+ data.tar.gz: 6e7d036234644964322c41dd0dcc4d8e9982c76c6abc4dd430c28a88431f635194da76826c153dcd249b6c0e4a0d26c2e2892b74f75f8063d7ece32fdb99cca7
data/.gitignore CHANGED
@@ -8,8 +8,6 @@
8
8
  /tmp/
9
9
  Gemfile.lock
10
10
  *.gem
11
- *.mp3
12
- test-data/
13
11
 
14
12
  # rspec failure tracking
15
13
  .rspec_status
data/.vscode/tasks.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "command": "bundle exec ruby exe/tag --auto_tag '/Users/mbaron/music2/Dinosaur Jr/Little Fury Things'"
28
28
  },
29
29
  {
30
- "label": "test-project",
30
+ "label": "rspec",
31
31
  "type": "shell",
32
32
  "presentation": {
33
33
  "clear": true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # UnitF::Tag
2
2
 
3
+ ## v0.2.0
4
+ - `UnitF::Tag::File` no longer inherits anything]
5
+ - Spec Tests
6
+
3
7
  ## v0.1.26
4
8
  - Completely re-do auto-tagging
5
9
 
data/bin/test.rb CHANGED
@@ -4,10 +4,7 @@ require 'unitf/tag'
4
4
 
5
5
  UnitF::Log.to_console
6
6
 
7
- # file = UnitF::Tag::File.new('/Users/mbaron/music2/BJ/2025/foo/bar/../../bj250321.mp3')
8
-
9
- # puts file.auto_tags
10
-
11
- # file.update do |f|
12
- # f.auto_tag!
13
- # end
7
+ UnitF::Tag.update('test-data/song.mp3') do |file|
8
+ puts "FILE: #{file}"
9
+ file.tag.artist = "Update #{Time.now.to_s}"
10
+ end
data/docs/taglib.md ADDED
@@ -0,0 +1,47 @@
1
+ # taglib Notes
2
+ Notes on `taglib` and `taglib-ruby` issues
3
+
4
+ **GitHub**
5
+ - https://github.com/taglib/taglib
6
+ - https://github.com/robinst/taglib-ruby
7
+
8
+ ## Custom TagLib 1.13.1 Build on MacOS
9
+ ```
10
+ curl -O https://taglib.org/releases/taglib-1.13.1.tar.gz
11
+ tar xvf taglib-1.13.1.tar.gz
12
+ cd taglib-1.13.1
13
+ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/taglib1 -DCMAKE_BUILD_TYPE=Release .
14
+ make
15
+ sudo make install
16
+ ```
17
+
18
+ ```
19
+ TAGLIB_DIR=/usr/local/taglib1 gem install taglib-ruby --version '< 2'
20
+ ```
21
+
22
+ ## Custom Build on Linux
23
+ ```
24
+ git clone https://github.com/taglib/taglib.git
25
+ cd taglib/
26
+ git submodule update --init
27
+ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/taglib -DCMAKE_BUILD_TYPE=Release .
28
+ make
29
+ make install
30
+ ```
31
+
32
+ ```
33
+ TAGLIB_DIR=/usr/local/taglib gem install taglib-ruby --version '>= 2'
34
+ ```
35
+
36
+ ### Taglib error w/ taglib 2.0.2
37
+ ```
38
+ root@homer:/nas/music2/WFMU# gem install /tmp/unitf-tag-0.1.27.gem
39
+ Successfully installed unitf-tag-0.1.27
40
+ Parsing documentation for unitf-tag-0.1.27
41
+ Installing ri documentation for unitf-tag-0.1.27
42
+ Done installing documentation for unitf-tag after 0 seconds
43
+ 1 gem installed
44
+ root@homer:/nas/music2/WFMU# tag
45
+ <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:136:in `require': /usr/local/lib64/gems/ruby/taglib-ruby-2.0.0/taglib_base.so: undefined symbol: _ZN6TagLib4File11removeBlockElm - /usr/local/lib64/gems/ruby/taglib-ruby-2.0.0/taglib_base.so (LoadError)
46
+ from <internal:/usr/share/rubygems/rubygems/core_ext/kernel_require.rb>:136:in `require'
47
+ ```
data/exe/tag CHANGED
@@ -100,21 +100,22 @@ end
100
100
 
101
101
  files.each do |file|
102
102
  UnitF::Log.info("Processing file: #{file}")
103
- file.update do |o|
104
- o.properties!(properties) unless properties.empty?
103
+
104
+ file.update do |f|
105
+ f.properties!(properties) unless properties.empty?
105
106
 
106
107
  actions.each do |action|
107
108
  case action
108
109
  when :cover
109
- o.cover!(opt[:cover])
110
+ f.cover!(opt[:cover])
110
111
  when :delete_cover
111
- o.delete_cover!
112
+ f.delete_cover!
112
113
  when :auto_cover
113
- o.auto_cover!
114
+ f.auto_cover!
114
115
  when :auto_tag
115
- o.auto_tag!
116
+ f.auto_tag!
116
117
  when :auto_tags
117
- puts "\tauto_tags: #{o.auto_tags}\n\n"
118
+ puts "\tauto_tags: #{f.auto_tags}\n\n"
118
119
  end
119
120
  end
120
121
  end
@@ -1,12 +1,11 @@
1
1
  module UnitF
2
2
  module Tag
3
3
  class AutoTags < Hash
4
- def initialize(pathname)
4
+ def initialize(file_path)
5
5
  super
6
6
 
7
- pathname = Pathname.new(pathname) if pathname.is_a?(String)
8
- @pathname = pathname.realpath
9
- @dirname = pathname.realpath.dirname
7
+ @file_path = ::File.realpath(file_path.to_s)
8
+ @dirname = ::File.dirname(@file_path)
10
9
 
11
10
  merge!(from_path)
12
11
  merge!(from_file)
@@ -25,7 +24,7 @@ module UnitF
25
24
  def from_path
26
25
  tags = {}
27
26
 
28
- tags[:title] = ::File.basename(@pathname)
27
+ tags[:title] = ::File.basename(@file_path)
29
28
  tags[:track] = tags[:title].match(/^\s*\d+/).to_s.to_i
30
29
 
31
30
  # Specific formatting for dated radio
@@ -39,7 +38,7 @@ module UnitF
39
38
 
40
39
  path_parts = @dirname.to_s.split('/')
41
40
  tags[:artist] = path_parts[-2]
42
- tags[:album] = tags[:album_artist] = path_parts[-1]
41
+ tags[:album] = path_parts[-1]
43
42
 
44
43
  tags
45
44
  end
@@ -6,24 +6,22 @@ require 'json'
6
6
 
7
7
  module UnitF
8
8
  module Tag
9
- class File < Pathname
10
- def initialize(file_path)
11
- super(::File.absolute_path(file_path.to_s))
12
- end
9
+ class File
10
+ attr_accessor :path, :realpath, :dirname, :extname
13
11
 
14
- def tag
15
- raise Error, "File is not open #{self.class.name}" if @file&.tag.nil?
12
+ def initialize(file_path)
13
+ raise Error, "Invalid file #{file_path}" unless ::File.exist?(file_path)
16
14
 
17
- @file&.tag
18
- end
15
+ @path = ::File.path(file_path.to_s)
16
+ @realpath = ::File.realpath(path)
17
+ @dirname = ::File.dirname(path)
18
+ @extname = ::File.extname(path)
19
19
 
20
- def save
21
- @file&.save
20
+ raise Error, "Unknown file type: #{file_path}" unless mp3? || flac?
22
21
  end
23
22
 
24
- def close
25
- @file&.close
26
- @file = nil
23
+ def to_s
24
+ @path
27
25
  end
28
26
 
29
27
  def format_json
@@ -40,7 +38,7 @@ module UnitF
40
38
 
41
39
  def info
42
40
  {
43
- file: realpath.to_path,
41
+ file: realpath,
44
42
  artist: tag.artist,
45
43
  album: tag.album,
46
44
  title: tag.title,
@@ -91,15 +89,18 @@ module UnitF
91
89
  true
92
90
  rescue StandardError => e
93
91
  UnitF::Log.error("Failed to auto-cover file #{e}")
92
+ puts e.backtrace
94
93
  false
95
94
  end
96
95
 
97
96
  def auto_tags
98
- @auto_tags ||= UnitF::Tag::AutoTags.new(self)
97
+ @auto_tags ||= UnitF::Tag::AutoTags.new(path)
99
98
  end
100
99
 
101
100
  def auto_tag!
102
101
  UnitF::Log.info("Auto tagging #{self}")
102
+ UnitF::Log.info(auto_tags)
103
+
103
104
  tag.album = auto_tags[:album]
104
105
  tag.artist = auto_tags[:artist]
105
106
  tag.title = auto_tags[:title]
@@ -116,21 +117,45 @@ module UnitF
116
117
  end
117
118
 
118
119
  def update
119
- open(auto_save: true) do |file|
120
- yield(file) if block_given?
120
+ open do |file|
121
+ if block_given?
122
+ yield(file)
123
+ file.save || (raise Error, "Failed to save file #{file}")
124
+ end
121
125
  end
122
126
  end
123
127
 
124
- def open(auto_save: false)
128
+ def open
125
129
  file = if flac?
126
- UnitF::Tag::FLAC.new(to_path)
127
- elsif mp3?
128
- UnitF::Tag::MP3.new(to_path)
129
- end
130
+ UnitF::Tag::FLAC.new(path)
131
+ elsif mp3?
132
+ UnitF::Tag::MP3.new(path)
133
+ end
130
134
  yield(file) if block_given?
131
- file.save if auto_save
132
135
  file.close
133
136
  end
137
+
138
+ #
139
+ # Methods that use @file, which comes from child classes
140
+ #
141
+ def tag
142
+ raise Error, "File is not open #{self.class.name}" if @file&.tag.nil?
143
+
144
+ @file&.tag
145
+ end
146
+
147
+ def save
148
+ raise Error, "File is not open #{self.class.name}" if @file&.tag.nil?
149
+
150
+ @file&.save
151
+ end
152
+
153
+ def close
154
+ raise Error, "File is not open #{self.class.name}" if @file&.tag.nil?
155
+
156
+ @file&.close
157
+ @file = nil
158
+ end
134
159
  end
135
160
  end
136
161
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = '0.1.27'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
data/lib/unitf/tag.rb CHANGED
@@ -16,7 +16,6 @@ module UnitF
16
16
  def update(file_path)
17
17
  UnitF::Tag::File.new(file_path).update do |file|
18
18
  yield file
19
- file.save || (raise UnitF::Tag::Error, "Failed to save file #{file_path}")
20
19
  end
21
20
  end
22
21
 
@@ -0,0 +1,2 @@
1
+ artist=Custom Artist
2
+ album=Custom Album
Binary file
Binary file
Binary file
Binary file
data/unitf-tag.gemspec CHANGED
@@ -1,10 +1,6 @@
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/)
8
4
 
9
5
  Gem::Specification.new do |spec|
10
6
  spec.name = 'unitf-tag'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitf-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.27
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Baron
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-27 00:00:00.000000000 Z
10
+ date: 2025-04-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: logger
@@ -71,6 +71,7 @@ files:
71
71
  - README.md
72
72
  - Rakefile
73
73
  - bin/test.rb
74
+ - docs/taglib.md
74
75
  - exe/tag
75
76
  - exe/unitf-autotags
76
77
  - lib/unitf/tag.rb
@@ -82,6 +83,12 @@ files:
82
83
  - lib/unitf/tag/helpers.rb
83
84
  - lib/unitf/tag/mp3.rb
84
85
  - lib/unitf/tag/version.rb
86
+ - test-data/Foo/Bar/.autotag
87
+ - test-data/Foo/Bar/2025/qq250916.mp3
88
+ - test-data/Test Artist/Test Album/04 - Test Song.mp3
89
+ - test-data/WFMU/BJ/2025/bj250915.mp3
90
+ - test-data/cover.jpg
91
+ - test-data/song.mp3
85
92
  - unitf-tag.gemspec
86
93
  homepage: https://github.com/mattbaron/unitf-tag
87
94
  licenses: