unitf-tag 0.1.4 → 0.1.6
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 +6 -3
- data/exe/rtag +10 -15
- data/lib/unitf/tag/export/exporter.rb +18 -0
- data/lib/unitf/tag/file.rb +26 -0
- data/lib/unitf/tag/fileset.rb +28 -0
- data/lib/unitf/tag/flac.rb +8 -0
- data/lib/unitf/tag/mp3.rb +8 -0
- data/lib/unitf/tag/version.rb +1 -1
- data/lib/unitf/tag.rb +25 -1
- data/unitf-tag.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3844f8f9883d9584a03a19be4ca9200c7b2203ec5b0f6d7615477d097d430628
|
4
|
+
data.tar.gz: 55e82e675756dbb52721575c888b0e3b7fb1bb2f0a59c9eb8b6557c657c54f2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb091d040bab764dda18aded5e23a7ed370f0b3b253a8b4b21b324b22a85b6ac079e6ce8fd530665f84fd9a0b30e454a846f7af64305b1bc601e988266bb4b31
|
7
|
+
data.tar.gz: 90448d8bf47f1973c1639c6fc81f18b258ed24e248f314f37a6d79a119e2e09420b14bede4c2276d6030bfeb7e7ec5f64929d9e51ee24c59ef662e9cccb315d2
|
data/.vscode/tasks.json
CHANGED
data/bin/test.rb
CHANGED
@@ -2,7 +2,10 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
require 'unitf/tag'
|
4
4
|
|
5
|
-
file_str = '/Users/mbaron/tag/music/fIREHOSE3/Sometimes'
|
6
|
-
file = UnitF::Tag::File.new(file_str)
|
5
|
+
file_str = '/Users/mbaron/tag/music/fIREHOSE3/Sometimes/01 - Sometimes.flac'
|
7
6
|
|
8
|
-
|
7
|
+
file = UnitF::Tag::FLAC.new(file_str)
|
8
|
+
|
9
|
+
file.open do |o|
|
10
|
+
pp o.info
|
11
|
+
end
|
data/exe/rtag
CHANGED
@@ -15,8 +15,6 @@ opt = {
|
|
15
15
|
force: false
|
16
16
|
}
|
17
17
|
|
18
|
-
UnitF::Tag.logger.level = Logger::INFO
|
19
|
-
|
20
18
|
targets = OptionParser.new do |opts|
|
21
19
|
opts.on('-r', '--recursive', 'Auto Cover') do
|
22
20
|
opt[:recursive] = true
|
@@ -30,6 +28,14 @@ targets = OptionParser.new do |opts|
|
|
30
28
|
UnitF::Tag.logger.level = Logger::DEBUG
|
31
29
|
end
|
32
30
|
|
31
|
+
opts.on('-j', '--json', 'JSON Output') do
|
32
|
+
opt[:format] = :json
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-l', '--line', 'Single Line Output') do
|
36
|
+
opt[:format] = :line
|
37
|
+
end
|
38
|
+
|
33
39
|
opts.on('--auto_cover', 'Auto Cover') do
|
34
40
|
actions << :auto_cover
|
35
41
|
end
|
@@ -67,25 +73,14 @@ targets = OptionParser.new do |opts|
|
|
67
73
|
end
|
68
74
|
end.parse!
|
69
75
|
|
70
|
-
|
71
|
-
files.concat(UnitF::Tag.process_target(target))
|
72
|
-
end
|
73
|
-
|
74
|
-
if files.size.zero? && actions.size.zero?
|
75
|
-
files = UnitF::Tag.find_files('.')
|
76
|
-
end
|
76
|
+
files = UnitF::Tag::FileSet.new(targets)
|
77
77
|
|
78
78
|
if files.size.zero?
|
79
79
|
logger.error('Cannot find any files to operate on')
|
80
80
|
end
|
81
81
|
|
82
82
|
if actions.size.zero?
|
83
|
-
files
|
84
|
-
file.open do |o|
|
85
|
-
o.print unless opt[:dump]
|
86
|
-
o.dump if opt[:dump]
|
87
|
-
end
|
88
|
-
end
|
83
|
+
UnitF::Tag.list(files, format: opt[:format])
|
89
84
|
exit 0
|
90
85
|
end
|
91
86
|
|
data/lib/unitf/tag/file.rb
CHANGED
@@ -2,6 +2,7 @@ require 'find'
|
|
2
2
|
require 'taglib'
|
3
3
|
require 'pathname'
|
4
4
|
require 'logger'
|
5
|
+
require 'json'
|
5
6
|
|
6
7
|
module UnitF
|
7
8
|
module Tag
|
@@ -14,6 +15,31 @@ module UnitF
|
|
14
15
|
@file.tag
|
15
16
|
end
|
16
17
|
|
18
|
+
def format_json
|
19
|
+
JSON.pretty_generate(info)
|
20
|
+
end
|
21
|
+
|
22
|
+
def format_line
|
23
|
+
buff = []
|
24
|
+
info.each_key do |key|
|
25
|
+
buff << "#{key}=#{info[key]}"
|
26
|
+
end
|
27
|
+
buff.join(',')
|
28
|
+
end
|
29
|
+
|
30
|
+
def info
|
31
|
+
{
|
32
|
+
file: realpath.to_path,
|
33
|
+
artist: tag.artist,
|
34
|
+
album: tag.album,
|
35
|
+
title: tag.title,
|
36
|
+
track: tag.track,
|
37
|
+
genre: tag.genre,
|
38
|
+
year: tag.year,
|
39
|
+
cover: cover?
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
17
43
|
def print
|
18
44
|
puts "File : #{realpath}"
|
19
45
|
puts "Artist: #{tag.artist}"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module UnitF
|
2
|
+
module Tag
|
3
|
+
class FileSet < Array
|
4
|
+
def initialize(targets)
|
5
|
+
targets.each do |target|
|
6
|
+
process_target(target)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def process_target(target)
|
11
|
+
if ::File.directory?(target)
|
12
|
+
find_files(target)
|
13
|
+
elsif UnitF::Tag.valid_file?(target)
|
14
|
+
append(UnitF::Tag::File.new(target))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_files(root_path)
|
19
|
+
Find.find(root_path) do |file_path|
|
20
|
+
UnitF::Log.debug("Considering #{file_path}")
|
21
|
+
next unless UnitF::Tag.valid_file?(file_path)
|
22
|
+
UnitF::Log.debug("Including #{file_path}")
|
23
|
+
append(UnitF::Tag::File.new(file_path))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/unitf/tag/flac.rb
CHANGED
@@ -6,6 +6,14 @@ module UnitF
|
|
6
6
|
@file = TagLib::FLAC::File.new(file_path)
|
7
7
|
end
|
8
8
|
|
9
|
+
def info
|
10
|
+
super.merge!({
|
11
|
+
stats: stats,
|
12
|
+
sample_rate: @file.audio_properties.sample_rate,
|
13
|
+
bits_per_sample: @file.audio_properties.bits_per_sample
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
9
17
|
def cover?
|
10
18
|
@file.picture_list.each do |pic|
|
11
19
|
return true if pic.type == TagLib::FLAC::Picture::FrontCover
|
data/lib/unitf/tag/mp3.rb
CHANGED
@@ -10,6 +10,14 @@ module UnitF
|
|
10
10
|
sprintf("%.1fkHz/%dkbps", @file.audio_properties.sample_rate / 1000.to_f, @file.audio_properties.bitrate)
|
11
11
|
end
|
12
12
|
|
13
|
+
def info
|
14
|
+
super.merge!({
|
15
|
+
stats: stats,
|
16
|
+
sample_rate: @file.audio_properties.sample_rate,
|
17
|
+
bitrate: @file.audio_properties.bitrate
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
13
21
|
def cover?
|
14
22
|
@file.id3v2_tag.frame_list('APIC').size > 0
|
15
23
|
end
|
data/lib/unitf/tag/version.rb
CHANGED
data/lib/unitf/tag.rb
CHANGED
@@ -2,16 +2,23 @@
|
|
2
2
|
|
3
3
|
require_relative 'tag/version'
|
4
4
|
require_relative 'tag/file'
|
5
|
+
require_relative 'tag/fileset'
|
5
6
|
require_relative 'tag/flac'
|
6
7
|
require_relative 'tag/mp3'
|
7
8
|
|
9
|
+
require 'unitf/logging'
|
10
|
+
|
8
11
|
module UnitF
|
9
12
|
module Tag
|
10
13
|
class Error < StandardError; end
|
11
14
|
class MissingCover < Error; end
|
12
15
|
|
13
16
|
def self.logger
|
14
|
-
@logger
|
17
|
+
unless @logger
|
18
|
+
@logger = UnitF::Logging::Logger.new
|
19
|
+
@logger.add_writer(UnitF::Logging::ConsoleWriter.new)
|
20
|
+
end
|
21
|
+
@logger
|
15
22
|
end
|
16
23
|
|
17
24
|
def self.valid_file?(file_path)
|
@@ -40,5 +47,22 @@ module UnitF
|
|
40
47
|
end
|
41
48
|
files
|
42
49
|
end
|
50
|
+
|
51
|
+
def self.list(files, format: :json)
|
52
|
+
buff = []
|
53
|
+
files.each do |file|
|
54
|
+
file.open do |o|
|
55
|
+
case format
|
56
|
+
when :json
|
57
|
+
buff << o.info
|
58
|
+
when :line
|
59
|
+
puts o.format_line
|
60
|
+
else
|
61
|
+
o.print
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts JSON.pretty_generate(buff) if format == :json
|
66
|
+
end
|
43
67
|
end
|
44
68
|
end
|
data/unitf-tag.gemspec
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Baron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: unitf-logging
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Audio File Tagging
|
28
42
|
email:
|
29
43
|
- mwb@unitf.net
|
@@ -47,7 +61,9 @@ files:
|
|
47
61
|
- bin/test.rb
|
48
62
|
- exe/rtag
|
49
63
|
- lib/unitf/tag.rb
|
64
|
+
- lib/unitf/tag/export/exporter.rb
|
50
65
|
- lib/unitf/tag/file.rb
|
66
|
+
- lib/unitf/tag/fileset.rb
|
51
67
|
- lib/unitf/tag/flac.rb
|
52
68
|
- lib/unitf/tag/mp3.rb
|
53
69
|
- lib/unitf/tag/version.rb
|
@@ -77,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
93
|
- !ruby/object:Gem::Version
|
78
94
|
version: '0'
|
79
95
|
requirements: []
|
80
|
-
rubygems_version: 3.2.
|
96
|
+
rubygems_version: 3.2.32
|
81
97
|
signing_key:
|
82
98
|
specification_version: 4
|
83
99
|
summary: Audio File Tagging
|