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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da63e27abbe2ad5f02751954906494623640d52ebee71c99cdde24e0e5cc9b45
4
- data.tar.gz: b6c8833b6a6c692fa584ba68e058cc0aa69f29b192d8d26b52bfa2c31e080dbb
3
+ metadata.gz: 3349c41222239a0d71175ea75b37345f768376f08d7b6621f5b28afc599804b9
4
+ data.tar.gz: 57ee77221f0b63bc6238d889fe2cf5b6c1de899a02f082b6443c49ccbfe5d1de
5
5
  SHA512:
6
- metadata.gz: 4e2bf3be1deb74914640c50e2fe3c424973742a48a0d006e889eae7b57b9cceb996897e1d431c02fe694fa2999a1f80fc161ef27fa1beab475f7d76e5eebd437
7
- data.tar.gz: da3d156c8dd3d507588d11e2eee893d24952ea31f611ac556010793442174f2a93b32f3b55e508d44a555b6125a7a2e799686962e12acbea2681af443980dd87
6
+ metadata.gz: 8aa4cc77d47945d7b8a5b53f2e5d979038ae2279e82f7cb4a31482f9f8e7205aab31249f17c8bccb30a6b260a3406c849059b56c399210eae22d61683eae0fe1
7
+ data.tar.gz: c6fd219e909d0baaa167902e7032109af3f164c522ed113c1c5fa109572342339b3efcf6549cc7133f9ec39c3a2764966b8350b1ef554a23f361dc14827d862d
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
10
+ *.gem
9
11
 
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/.rubocop.yml CHANGED
@@ -7,3 +7,8 @@ Style/Documentation:
7
7
  Style/FrozenStringLiteralComment:
8
8
  Enabled: false
9
9
 
10
+ Metrics/MethodLength:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
data/.vscode/tasks.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "presentation": {
17
17
  "clear": true
18
18
  },
19
- "command": "bundle exec ruby exe/rtag /Users/mbaron/tag/music"
19
+ "command": "bundle exec ruby bin/test.rb"
20
20
  },
21
21
  {
22
22
  "label": "test-project",
data/bin/test.rb CHANGED
@@ -2,10 +2,9 @@ require 'optparse'
2
2
 
3
3
  require 'unitf/tag'
4
4
 
5
- file_str = '/Users/mbaron/tag/music/fIREHOSE3/Sometimes/01 - Sometimes.flac'
5
+ UnitF::Log.to_console
6
6
 
7
- file = UnitF::Tag::FLAC.new(file_str)
8
-
9
- file.open do |o|
10
- pp o.info
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
- logger = Logger.new($stdout)
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
- logger.error('Cannot find any files to operate on')
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
- logger.info("Processing file: #{file}")
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
- logger.info('Delete cover')
96
+ UnitF::Log.info('Delete cover')
91
97
  o.delete_cover!
92
98
  when :auto_cover
93
99
  unless o.cover?
94
- logger.info("Auto Cover #{file.cover_path}")
100
+ UnitF::Log.info("Auto Cover #{file.cover_path}")
95
101
  begin
96
102
  o.auto_cover!
97
103
  rescue => e
98
- logger.error("Failed to auto-cover file #{e}")
104
+ UnitF::Log.error("Failed to auto-cover file #{e}")
99
105
  end
100
106
  end
101
107
  when :auto_tag
102
- logger.info('Auto Tag')
108
+ UnitF::Log.info('Auto Tag')
103
109
  o.auto_tag!
104
110
  when :artist
105
- logger.info("Setting artist to #{opt[:artist]}")
111
+ UnitF::Log.info("Setting artist to #{opt[:artist]}")
106
112
  o.tag.artist = opt[:artist]
107
113
  when :album
108
- logger.info("Setting album to #{opt[:album]}")
114
+ UnitF::Log.info("Setting album to #{opt[:album]}")
109
115
  o.tag.album = opt[:album]
110
116
  when :title
111
- logger.info("Setting title to #{opt[:title]}")
117
+ UnitF::Log.info("Setting title to #{opt[:title]}")
112
118
  o.tag.title = opt[:title]
113
119
  when :genre
114
- logger.info("Setting genre to #{opt[:genre]}")
120
+ UnitF::Log.info("Setting genre to #{opt[:genre]}")
115
121
  o.tag.genre = opt[:genre]
116
122
  when :track
117
- logger.info("Setting track to #{opt[:track]}")
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 || logger.error("Unable to save changes to #{file}")
130
+ o.save || UnitF::Log.error("Unable to save changes to #{file}")
122
131
  end
123
132
  end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.9"
6
6
  end
7
7
  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.7
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: 2021-12-05 00:00:00.000000000 Z
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.2.22
94
+ rubygems_version: 3.3.26
97
95
  signing_key:
98
96
  specification_version: 4
99
97
  summary: Audio File Tagging
data/tag DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
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