unitf-tag 0.1.7 → 0.1.9
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/.gitignore +2 -0
- data/.rubocop.yml +5 -0
- data/.vscode/tasks.json +1 -1
- data/bin/test.rb +5 -6
- data/exe/tag +22 -13
- data/lib/unitf/tag/file.rb +47 -0
- data/lib/unitf/tag/version.rb +1 -1
- metadata +3 -5
- data/tag +0 -2
- data/test.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3349c41222239a0d71175ea75b37345f768376f08d7b6621f5b28afc599804b9
|
4
|
+
data.tar.gz: 57ee77221f0b63bc6238d889fe2cf5b6c1de899a02f082b6443c49ccbfe5d1de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa4cc77d47945d7b8a5b53f2e5d979038ae2279e82f7cb4a31482f9f8e7205aab31249f17c8bccb30a6b260a3406c849059b56c399210eae22d61683eae0fe1
|
7
|
+
data.tar.gz: c6fd219e909d0baaa167902e7032109af3f164c522ed113c1c5fa109572342339b3efcf6549cc7133f9ec39c3a2764966b8350b1ef554a23f361dc14827d862d
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.vscode/tasks.json
CHANGED
data/bin/test.rb
CHANGED
@@ -2,10 +2,9 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
require 'unitf/tag'
|
4
4
|
|
5
|
-
|
5
|
+
UnitF::Log.to_console
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
UnitF::Tag::File.update('/Users/mbaron/tmp/foo.mp3') do |tag|
|
8
|
+
tag.artist = 'bar123'
|
9
|
+
tag.year = 1972
|
10
|
+
end
|
data/exe/tag
CHANGED
@@ -5,8 +5,9 @@ $LOAD_PATH.unshift("#{__dir__}/../lib")
|
|
5
5
|
require 'logger'
|
6
6
|
require 'optparse'
|
7
7
|
require 'unitf/tag'
|
8
|
+
require 'unitf/logging'
|
8
9
|
|
9
|
-
|
10
|
+
UnitF::Log.to_console
|
10
11
|
|
11
12
|
actions = []
|
12
13
|
files = []
|
@@ -64,6 +65,11 @@ targets = OptionParser.new do |opts|
|
|
64
65
|
opt[:title] = arg
|
65
66
|
end
|
66
67
|
|
68
|
+
opts.on('--year YEAR', 'Song Year') do |arg|
|
69
|
+
actions << :year
|
70
|
+
opt[:year] = arg.to_i
|
71
|
+
end
|
72
|
+
|
67
73
|
opts.on('--genre GENRE', 'Genre') do |arg|
|
68
74
|
actions << :genre
|
69
75
|
opt[:genre] = arg
|
@@ -73,7 +79,7 @@ end.parse!
|
|
73
79
|
files = UnitF::Tag::FileSet.new(targets)
|
74
80
|
|
75
81
|
if files.size.zero?
|
76
|
-
|
82
|
+
UnitF::Log.error('Cannot find any files to operate on')
|
77
83
|
end
|
78
84
|
|
79
85
|
if actions.size.zero?
|
@@ -82,42 +88,45 @@ if actions.size.zero?
|
|
82
88
|
end
|
83
89
|
|
84
90
|
files.each do |file|
|
85
|
-
|
91
|
+
UnitF::Log.info("Processing file: #{file}")
|
86
92
|
file.open do |o|
|
87
93
|
actions.each do |action|
|
88
94
|
case action
|
89
95
|
when :delete_cover
|
90
|
-
|
96
|
+
UnitF::Log.info('Delete cover')
|
91
97
|
o.delete_cover!
|
92
98
|
when :auto_cover
|
93
99
|
unless o.cover?
|
94
|
-
|
100
|
+
UnitF::Log.info("Auto Cover #{file.cover_path}")
|
95
101
|
begin
|
96
102
|
o.auto_cover!
|
97
103
|
rescue => e
|
98
|
-
|
104
|
+
UnitF::Log.error("Failed to auto-cover file #{e}")
|
99
105
|
end
|
100
106
|
end
|
101
107
|
when :auto_tag
|
102
|
-
|
108
|
+
UnitF::Log.info('Auto Tag')
|
103
109
|
o.auto_tag!
|
104
110
|
when :artist
|
105
|
-
|
111
|
+
UnitF::Log.info("Setting artist to #{opt[:artist]}")
|
106
112
|
o.tag.artist = opt[:artist]
|
107
113
|
when :album
|
108
|
-
|
114
|
+
UnitF::Log.info("Setting album to #{opt[:album]}")
|
109
115
|
o.tag.album = opt[:album]
|
110
116
|
when :title
|
111
|
-
|
117
|
+
UnitF::Log.info("Setting title to #{opt[:title]}")
|
112
118
|
o.tag.title = opt[:title]
|
113
119
|
when :genre
|
114
|
-
|
120
|
+
UnitF::Log.info("Setting genre to #{opt[:genre]}")
|
115
121
|
o.tag.genre = opt[:genre]
|
116
122
|
when :track
|
117
|
-
|
123
|
+
UnitF::Log.info("Setting track to #{opt[:track]}")
|
118
124
|
o.tag.genre = opt[:track]
|
125
|
+
when :year
|
126
|
+
UnitF::Log.info("Setting year to #{opt[:year]}")
|
127
|
+
o.tag.year = opt[:year]
|
119
128
|
end
|
120
129
|
end
|
121
|
-
o.save ||
|
130
|
+
o.save || UnitF::Log.error("Unable to save changes to #{file}")
|
122
131
|
end
|
123
132
|
end
|
data/lib/unitf/tag/file.rb
CHANGED
@@ -11,6 +11,20 @@ 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
|
+
|
14
28
|
def tag
|
15
29
|
@file.tag
|
16
30
|
end
|
@@ -77,7 +91,40 @@ module UnitF
|
|
77
91
|
cover!(cover_path)
|
78
92
|
end
|
79
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
|
108
|
+
|
109
|
+
def auto_tags
|
110
|
+
manual_tags = manual_auto_tags
|
111
|
+
tags = {}
|
112
|
+
|
113
|
+
tags[:title] = ::File.basename(realpath.to_path)
|
114
|
+
track = tags[:title].match(/^\s*\d+/).to_s.to_i
|
115
|
+
tags[:title].gsub!(/\.\w+$/, '')
|
116
|
+
tags[:title].gsub!(/^\d*\s*(-|\.)*\s*/, '')
|
117
|
+
path_parts = realpath.dirname.to_path.split('/')
|
118
|
+
tags[:album] = path_parts[-1]
|
119
|
+
tags[:artist] = path_parts[-2]
|
120
|
+
|
121
|
+
tags.merge(manual_auto_tags)
|
122
|
+
end
|
123
|
+
|
80
124
|
def auto_tag!
|
125
|
+
UnitF::Log.info("Auto tagging #{to_s}")
|
126
|
+
manual_auto_tags
|
127
|
+
|
81
128
|
title = ::File.basename(realpath.to_path)
|
82
129
|
|
83
130
|
# This must come before gsubbing the title
|
data/lib/unitf/tag/version.rb
CHANGED
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.9
|
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: 2022-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -67,8 +67,6 @@ files:
|
|
67
67
|
- lib/unitf/tag/flac.rb
|
68
68
|
- lib/unitf/tag/mp3.rb
|
69
69
|
- lib/unitf/tag/version.rb
|
70
|
-
- tag
|
71
|
-
- test.rb
|
72
70
|
- unitf-tag.gemspec
|
73
71
|
homepage: https://github.com/mattbaron/unitf-tag
|
74
72
|
licenses:
|
@@ -93,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
91
|
- !ruby/object:Gem::Version
|
94
92
|
version: '0'
|
95
93
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
94
|
+
rubygems_version: 3.3.26
|
97
95
|
signing_key:
|
98
96
|
specification_version: 4
|
99
97
|
summary: Audio File Tagging
|
data/test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'find'
|
2
|
-
|
3
|
-
require 'unitf/tagger'
|
4
|
-
|
5
|
-
file_str = '../../tag/music/If\'n/01-Sometimes.mp3'
|
6
|
-
file_str = '/Users/mbaron/tmp/foo-bar.txt'
|
7
|
-
|
8
|
-
# begin
|
9
|
-
# file = File.new(file_str)
|
10
|
-
# rescue Errno::ENOENT => e
|
11
|
-
# puts "No such file #{file_str}"
|
12
|
-
# end
|
13
|
-
|
14
|
-
#puts Dir.glob('/Users/mbaron/google-cloud-sdk/**/*')
|
15
|
-
|
16
|
-
Find.find('../../tag/music') do |path|
|
17
|
-
next unless File.file?(path)
|
18
|
-
file = UnitF::Tagger::AudioFile.new(path)
|
19
|
-
puts file.cover_path
|
20
|
-
end
|