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 +4 -4
- data/.vscode/tasks.json +1 -1
- data/bin/test.rb +4 -3
- data/exe/tag +20 -2
- data/exe/unitf-autotags +17 -0
- data/lib/unitf/tag/file.rb +28 -54
- data/lib/unitf/tag/version.rb +1 -1
- data/lib/unitf/tag.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b16a3b7f4448536620cf9bc5ac134c082a9bfd61a7bd57e685d254397d97412
|
4
|
+
data.tar.gz: 253ac7cc3eabd4e6a812c76588854aff868aac9dd422434a0fc0175a55adab0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58f21090b63069f22238a98a75b8545f6a2652428982025b562ef73ef80fdd7af54b363887c60be2f13f124dc0e33853d59e2e8778b533b600280e3624ca3848
|
7
|
+
data.tar.gz: 013d2107a8fe2ce6b68b15f6a5d490cda5a4b2b90d591641c062519172f4c63874834fc30d2f68bbf81ae330622849e83aaf034db31045ea8b530778a954581c
|
data/.vscode/tasks.json
CHANGED
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
|
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(
|
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.
|
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]
|
data/exe/unitf-autotags
ADDED
@@ -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
|
data/lib/unitf/tag/file.rb
CHANGED
@@ -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
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
title =
|
129
|
-
|
130
|
-
|
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
|
data/lib/unitf/tag/version.rb
CHANGED
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.
|
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:
|
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
|