unitf-tag 0.1.9 → 0.1.16

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: 3349c41222239a0d71175ea75b37345f768376f08d7b6621f5b28afc599804b9
4
- data.tar.gz: 57ee77221f0b63bc6238d889fe2cf5b6c1de899a02f082b6443c49ccbfe5d1de
3
+ metadata.gz: 7b16a3b7f4448536620cf9bc5ac134c082a9bfd61a7bd57e685d254397d97412
4
+ data.tar.gz: 253ac7cc3eabd4e6a812c76588854aff868aac9dd422434a0fc0175a55adab0b
5
5
  SHA512:
6
- metadata.gz: 8aa4cc77d47945d7b8a5b53f2e5d979038ae2279e82f7cb4a31482f9f8e7205aab31249f17c8bccb30a6b260a3406c849059b56c399210eae22d61683eae0fe1
7
- data.tar.gz: c6fd219e909d0baaa167902e7032109af3f164c522ed113c1c5fa109572342339b3efcf6549cc7133f9ec39c3a2764966b8350b1ef554a23f361dc14827d862d
6
+ metadata.gz: 58f21090b63069f22238a98a75b8545f6a2652428982025b562ef73ef80fdd7af54b363887c60be2f13f124dc0e33853d59e2e8778b533b600280e3624ca3848
7
+ data.tar.gz: 013d2107a8fe2ce6b68b15f6a5d490cda5a4b2b90d591641c062519172f4c63874834fc30d2f68bbf81ae330622849e83aaf034db31045ea8b530778a954581c
data/.vscode/tasks.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "presentation": {
17
17
  "clear": true
18
18
  },
19
- "command": "bundle exec ruby bin/test.rb"
19
+ "command": "bundle exec ruby exe/tag --dump /Users/mbaron/Desktop/sb/*"
20
20
  },
21
21
  {
22
22
  "label": "test-project",
data/bin/test.rb CHANGED
@@ -4,7 +4,8 @@ require 'unitf/tag'
4
4
 
5
5
  UnitF::Log.to_console
6
6
 
7
- UnitF::Tag::File.update('/Users/mbaron/tmp/foo.mp3') do |tag|
8
- tag.artist = 'bar123'
9
- tag.year = 1972
7
+ UnitF::Tag.update('/Users/mbaron/tmp/foo.mp3') do |file|
8
+ file.tag.artist = 'bar123'
9
+ file.tag.year = 1972
10
+ file.auto_cover!
10
11
  end
data/exe/tag CHANGED
@@ -13,6 +13,8 @@ actions = []
13
13
  files = []
14
14
  opt = {}
15
15
 
16
+ no_args = ARGV.size.zero?
17
+
16
18
  targets = OptionParser.new do |opts|
17
19
  opts.on('-r', '--recursive', 'Auto Cover') do
18
20
  opt[:recursive] = true
@@ -34,6 +36,12 @@ targets = OptionParser.new do |opts|
34
36
  opt[:format] = :line
35
37
  end
36
38
 
39
+ opts.on('--cover COVER', 'Cover') do |arg|
40
+ actions << :cover
41
+ raise "Invalid cover file #{arg}" unless ::File.exist?(arg) && arg.downcase.end_with?('.jpg')
42
+ opt[:cover] = arg
43
+ end
44
+
37
45
  opts.on('--auto_cover', 'Auto Cover') do
38
46
  actions << :auto_cover
39
47
  end
@@ -74,8 +82,15 @@ targets = OptionParser.new do |opts|
74
82
  actions << :genre
75
83
  opt[:genre] = arg
76
84
  end
85
+
86
+ opts.on('--track TRACK', 'Song Track') do |arg|
87
+ actions << :track
88
+ opt[:track] = arg.to_i
89
+ end
77
90
  end.parse!
78
91
 
92
+ targets = Dir.glob('*') if no_args
93
+
79
94
  files = UnitF::Tag::FileSet.new(targets)
80
95
 
81
96
  if files.size.zero?
@@ -92,6 +107,9 @@ files.each do |file|
92
107
  file.open do |o|
93
108
  actions.each do |action|
94
109
  case action
110
+ when :cover
111
+ UnitF::Log.info("Cover #{opt[:cover]}")
112
+ o.cover!(opt[:cover])
95
113
  when :delete_cover
96
114
  UnitF::Log.info('Delete cover')
97
115
  o.delete_cover!
@@ -105,7 +123,7 @@ files.each do |file|
105
123
  end
106
124
  end
107
125
  when :auto_tag
108
- UnitF::Log.info('Auto Tag')
126
+ UnitF::Log.info("Auto Tag #{file}")
109
127
  o.auto_tag!
110
128
  when :artist
111
129
  UnitF::Log.info("Setting artist to #{opt[:artist]}")
@@ -121,7 +139,7 @@ files.each do |file|
121
139
  o.tag.genre = opt[:genre]
122
140
  when :track
123
141
  UnitF::Log.info("Setting track to #{opt[:track]}")
124
- o.tag.genre = opt[:track]
142
+ o.tag.track = opt[:track]
125
143
  when :year
126
144
  UnitF::Log.info("Setting year to #{opt[:year]}")
127
145
  o.tag.year = opt[:year]
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'logger'
6
+ require 'optparse'
7
+ require 'unitf/tag'
8
+ require 'unitf/logging'
9
+
10
+ UnitF::Log.to_console
11
+
12
+ files = UnitF::Tag::FileSet.new(ARGV)
13
+
14
+ files.each do |file|
15
+ puts "File: #{file}"
16
+ puts "Tags: #{file.auto_tags}"
17
+ end
@@ -11,20 +11,6 @@ module UnitF
11
11
  super(::File.absolute_path(file_path.to_s))
12
12
  end
13
13
 
14
- def update
15
- open do |file|
16
- yield file.tag
17
- file.save || (raise UnitF::Tag::Error, "Failed to save file #{@file}")
18
- end
19
- end
20
-
21
- def self.update(file_path)
22
- UnitF::Tag::File.new(file_path).open do |file|
23
- yield file.tag
24
- file.save || (raise UnitF::Tag::Error, "Failed to save file #{file_path}")
25
- end
26
- end
27
-
28
14
  def tag
29
15
  @file.tag
30
16
  end
@@ -72,7 +58,7 @@ module UnitF
72
58
  end
73
59
 
74
60
  def auto_tag_path
75
- "#{dirname}/.autotag"
61
+ "#{dirname}/.autotag.json"
76
62
  end
77
63
 
78
64
  def mp3?
@@ -88,26 +74,24 @@ module UnitF
88
74
  end
89
75
 
90
76
  def auto_cover!
91
- cover!(cover_path)
92
- end
93
-
94
- def manual_auto_tags
95
- UnitF::Log.info(auto_tag_path)
96
- tags = {}
97
- return {} unless ::File.exist?(auto_tag_path)
98
- ::File.read(auto_tag_path).each_line do |line|
99
- line.chomp!
100
- UnitF::Log.info(line)
101
- tag, value = line.split(/\s*=\s*/)
102
- tags[tag.to_sym] = value
103
- end
104
- tags
105
- rescue
106
- {}
107
- end
77
+ cover!(cover_path) if cover_available?
78
+ end
79
+
80
+ # def auto_tag_override
81
+ # tags = {}
82
+ # return {} unless ::File.exist?(auto_tag_path)
83
+ # ::File.read(auto_tag_path).each_line do |line|
84
+ # line.strip!
85
+ # # UnitF::Log.info(line)
86
+ # tag, value = line.split(/\s*=\s*/)
87
+ # tags[tag.to_sym] = value
88
+ # end
89
+ # tags
90
+ # rescue
91
+ # {}
92
+ # end
108
93
 
109
94
  def auto_tags
110
- manual_tags = manual_auto_tags
111
95
  tags = {}
112
96
 
113
97
  tags[:title] = ::File.basename(realpath.to_path)
@@ -118,30 +102,20 @@ module UnitF
118
102
  tags[:album] = path_parts[-1]
119
103
  tags[:artist] = path_parts[-2]
120
104
 
121
- tags.merge(manual_auto_tags)
105
+ begin
106
+ tags.merge!(JSON.parse(::File.read(auto_tag_path), symbolize_names: true))
107
+ rescue; end
108
+
109
+ tags
122
110
  end
123
111
 
124
112
  def auto_tag!
125
- UnitF::Log.info("Auto tagging #{to_s}")
126
- manual_auto_tags
127
-
128
- title = ::File.basename(realpath.to_path)
129
-
130
- # This must come before gsubbing the title
131
- track = title.match(/^\s*\d+/).to_s.to_i
132
-
133
- title.gsub!(/\.\w+$/, '')
134
- title.gsub!(/^\d*\s*(-|\.)*\s*/, '')
135
-
136
- path_parts = realpath.dirname.to_path.split('/')
137
- album = path_parts[-1]
138
- artist = path_parts[-2]
139
-
140
- tag.album = album
141
- tag.artist = artist
142
- tag.title = title
143
- tag.track = track
144
- self.album_artist = artist
113
+ tags = auto_tags
114
+ tag.album = tags[:album]
115
+ tag.artist = tags[:artist]
116
+ tag.title = tags[:title]
117
+ tag.track = tags[:track] unless tags[:track].nil?
118
+ self.album_artist = tags[:artist]
145
119
  end
146
120
 
147
121
  def save
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = "0.1.9"
5
+ VERSION = "0.1.16"
6
6
  end
7
7
  end
data/lib/unitf/tag.rb CHANGED
@@ -21,6 +21,13 @@ module UnitF
21
21
  @logger
22
22
  end
23
23
 
24
+ def self.update(file_path)
25
+ UnitF::Tag::File.new(file_path).open do |file|
26
+ yield file
27
+ file.save || (raise UnitF::Tag::Error, "Failed to save file #{file_path}")
28
+ end
29
+ end
30
+
24
31
  def self.valid_file?(file_path)
25
32
  ::File.file?(file_path) && file_path.encode.match(/\.(flac|mp3)$/i)
26
33
  rescue ArgumentError => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitf-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Baron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-11 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -43,6 +43,7 @@ email:
43
43
  - mwb@unitf.net
44
44
  executables:
45
45
  - tag
46
+ - unitf-autotags
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -60,6 +61,7 @@ files:
60
61
  - bin/setup
61
62
  - bin/test.rb
62
63
  - exe/tag
64
+ - exe/unitf-autotags
63
65
  - lib/unitf/tag.rb
64
66
  - lib/unitf/tag/export/exporter.rb
65
67
  - lib/unitf/tag/file.rb