unitf-tag 0.1.2 → 0.1.7

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: 423a0e318af5b1d062e7b933b7487278d48ae1e0933c01663d2dff50aa59128a
4
- data.tar.gz: a770fbd8c7762769571fddc563b78b6834c044a1deae55ac1d7d9b8bacbbfbb1
3
+ metadata.gz: da63e27abbe2ad5f02751954906494623640d52ebee71c99cdde24e0e5cc9b45
4
+ data.tar.gz: b6c8833b6a6c692fa584ba68e058cc0aa69f29b192d8d26b52bfa2c31e080dbb
5
5
  SHA512:
6
- metadata.gz: 05dab0beb32b35c410b37bd536a26e30f45fa3fa9ca59c271dac272967ed69f1c75bc0890c325c83dfdc954722de69d6e63f00511623d9d9bdc0ada48fe5728c
7
- data.tar.gz: 3d53e61c391f23bf1675e9787dfdd09489f9a660d0b2b7fadb9c1cd5487887892e6018846b7a4402eb0a578c643a5076dcd33f0954078a6c2d31877b65b66415
6
+ metadata.gz: 4e2bf3be1deb74914640c50e2fe3c424973742a48a0d006e889eae7b57b9cceb996897e1d431c02fe694fa2999a1f80fc161ef27fa1beab475f7d76e5eebd437
7
+ data.tar.gz: da3d156c8dd3d507588d11e2eee893d24952ea31f611ac556010793442174f2a93b32f3b55e508d44a555b6125a7a2e799686962e12acbea2681af443980dd87
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/rtag /Users/mbaron/tag/music"
20
20
  },
21
21
  {
22
22
  "label": "test-project",
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
- puts file.to_s
7
+ file = UnitF::Tag::FLAC.new(file_str)
8
+
9
+ file.open do |o|
10
+ pp o.info
11
+ end
data/exe/{rtag → tag} RENAMED
@@ -10,12 +10,7 @@ logger = Logger.new($stdout)
10
10
 
11
11
  actions = []
12
12
  files = []
13
- opt = {
14
- recursive: false,
15
- force: false
16
- }
17
-
18
- UnitF::Tag.logger.level = Logger::INFO
13
+ opt = {}
19
14
 
20
15
  targets = OptionParser.new do |opts|
21
16
  opts.on('-r', '--recursive', 'Auto Cover') do
@@ -30,6 +25,14 @@ targets = OptionParser.new do |opts|
30
25
  UnitF::Tag.logger.level = Logger::DEBUG
31
26
  end
32
27
 
28
+ opts.on('-j', '--json', 'JSON Output') do
29
+ opt[:format] = :json
30
+ end
31
+
32
+ opts.on('-l', '--line', 'Single Line Output') do
33
+ opt[:format] = :line
34
+ end
35
+
33
36
  opts.on('--auto_cover', 'Auto Cover') do
34
37
  actions << :auto_cover
35
38
  end
@@ -67,25 +70,14 @@ targets = OptionParser.new do |opts|
67
70
  end
68
71
  end.parse!
69
72
 
70
- targets.each do |target|
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
73
+ files = UnitF::Tag::FileSet.new(targets)
77
74
 
78
75
  if files.size.zero?
79
76
  logger.error('Cannot find any files to operate on')
80
77
  end
81
78
 
82
79
  if actions.size.zero?
83
- files.each do |file|
84
- file.open do |o|
85
- o.print unless opt[:dump]
86
- o.dump if opt[:dump]
87
- end
88
- end
80
+ UnitF::Tag.list(files, format: opt[:format])
89
81
  exit 0
90
82
  end
91
83
 
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ module UnitF
4
+ module Tag
5
+ class Exporter
6
+ def initialize
7
+ @objects = []
8
+ end
9
+
10
+ def spool(object)
11
+ end
12
+
13
+ def dump
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.7"
6
6
  end
7
7
  end
data/lib/unitf/tag.rb CHANGED
@@ -2,20 +2,30 @@
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 ||= Logger.new($stdout)
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)
18
- ::File.file?(file_path) && file_path.match(/\.(flac|mp3)$/i)
25
+ ::File.file?(file_path) && file_path.encode.match(/\.(flac|mp3)$/i)
26
+ rescue ArgumentError => e
27
+ logger.error("Error processing #{file_path} - #{e.message}")
28
+ false
19
29
  end
20
30
 
21
31
  def self.process_target(target)
@@ -37,5 +47,22 @@ module UnitF
37
47
  end
38
48
  files
39
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
40
67
  end
41
68
  end
data/unitf-tag.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_dependency "taglib-ruby"
31
+ spec.add_dependency "unitf-logging"
31
32
  end
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.2
4
+ version: 0.1.7
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-27 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -24,11 +24,25 @@ 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
30
44
  executables:
31
- - rtag
45
+ - tag
32
46
  extensions: []
33
47
  extra_rdoc_files: []
34
48
  files:
@@ -45,13 +59,14 @@ files:
45
59
  - bin/console
46
60
  - bin/setup
47
61
  - bin/test.rb
48
- - exe/rtag
62
+ - exe/tag
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
54
- - lib/unitf/version.rb
55
70
  - tag
56
71
  - test.rb
57
72
  - unitf-tag.gemspec
data/lib/unitf/version.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unitf
4
- module Tagger
5
- VERSION = "0.1.0"
6
- end
7
- end