unitf-tag 0.1.6 → 0.1.8

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: 3844f8f9883d9584a03a19be4ca9200c7b2203ec5b0f6d7615477d097d430628
4
- data.tar.gz: 55e82e675756dbb52721575c888b0e3b7fb1bb2f0a59c9eb8b6557c657c54f2a
3
+ metadata.gz: 68404fe4f09503662b8fa2f52479ce65d14f5c9eea0d6928e99a10599c468be8
4
+ data.tar.gz: 398a8ea66bcfa0dcc33d3fafb1e51f6fcd305c4377644df6a3d5ad94f3786647
5
5
  SHA512:
6
- metadata.gz: eb091d040bab764dda18aded5e23a7ed370f0b3b253a8b4b21b324b22a85b6ac079e6ce8fd530665f84fd9a0b30e454a846f7af64305b1bc601e988266bb4b31
7
- data.tar.gz: 90448d8bf47f1973c1639c6fc81f18b258ed24e248f314f37a6d79a119e2e09420b14bede4c2276d6030bfeb7e7ec5f64929d9e51ee24c59ef662e9cccb315d2
6
+ metadata.gz: 94f7d7c34b182095ea849846ebbb811e2f964d50d74aff54a8e9648193b366ada30028216440f53a96ce3b7133a4d40e9cdf2ee565479df5b07a15958b174a0b
7
+ data.tar.gz: 0475211c72702358a985acece10e4af18ac3f36c2d3869807f329a03391d80b16e64968d2aa852b4c55a70776c3ec149aec091fd7336cf77ae076858617fe04c
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
9
10
 
10
11
  # rspec failure tracking
11
12
  .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'
6
-
7
- file = UnitF::Tag::FLAC.new(file_str)
5
+ UnitF::Log.to_console
8
6
 
7
+ file = UnitF::Tag::File.new('/Users/mbaron/tmp/WFMU/BJ/bj211119.mp3')
9
8
  file.open do |o|
10
- pp o.info
9
+ puts o.auto_tags
11
10
  end
data/exe/{rtag → tag} RENAMED
@@ -5,15 +5,13 @@ $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 = []
13
- opt = {
14
- recursive: false,
15
- force: false
16
- }
14
+ opt = {}
17
15
 
18
16
  targets = OptionParser.new do |opts|
19
17
  opts.on('-r', '--recursive', 'Auto Cover') do
@@ -67,6 +65,11 @@ targets = OptionParser.new do |opts|
67
65
  opt[:title] = arg
68
66
  end
69
67
 
68
+ opts.on('--year YEAR', 'Song Year') do |arg|
69
+ actions << :year
70
+ opt[:year] = arg.to_i
71
+ end
72
+
70
73
  opts.on('--genre GENRE', 'Genre') do |arg|
71
74
  actions << :genre
72
75
  opt[:genre] = arg
@@ -76,7 +79,7 @@ end.parse!
76
79
  files = UnitF::Tag::FileSet.new(targets)
77
80
 
78
81
  if files.size.zero?
79
- logger.error('Cannot find any files to operate on')
82
+ UnitF::Log.error('Cannot find any files to operate on')
80
83
  end
81
84
 
82
85
  if actions.size.zero?
@@ -85,42 +88,45 @@ if actions.size.zero?
85
88
  end
86
89
 
87
90
  files.each do |file|
88
- logger.info("Processing file: #{file}")
91
+ UnitF::Log.info("Processing file: #{file}")
89
92
  file.open do |o|
90
93
  actions.each do |action|
91
94
  case action
92
95
  when :delete_cover
93
- logger.info('Delete cover')
96
+ UnitF::Log.info('Delete cover')
94
97
  o.delete_cover!
95
98
  when :auto_cover
96
99
  unless o.cover?
97
- logger.info("Auto Cover #{file.cover_path}")
100
+ UnitF::Log.info("Auto Cover #{file.cover_path}")
98
101
  begin
99
102
  o.auto_cover!
100
103
  rescue => e
101
- logger.error("Failed to auto-cover file #{e}")
104
+ UnitF::Log.error("Failed to auto-cover file #{e}")
102
105
  end
103
106
  end
104
107
  when :auto_tag
105
- logger.info('Auto Tag')
108
+ UnitF::Log.info('Auto Tag')
106
109
  o.auto_tag!
107
110
  when :artist
108
- logger.info("Setting artist to #{opt[:artist]}")
111
+ UnitF::Log.info("Setting artist to #{opt[:artist]}")
109
112
  o.tag.artist = opt[:artist]
110
113
  when :album
111
- logger.info("Setting album to #{opt[:album]}")
114
+ UnitF::Log.info("Setting album to #{opt[:album]}")
112
115
  o.tag.album = opt[:album]
113
116
  when :title
114
- logger.info("Setting title to #{opt[:title]}")
117
+ UnitF::Log.info("Setting title to #{opt[:title]}")
115
118
  o.tag.title = opt[:title]
116
119
  when :genre
117
- logger.info("Setting genre to #{opt[:genre]}")
120
+ UnitF::Log.info("Setting genre to #{opt[:genre]}")
118
121
  o.tag.genre = opt[:genre]
119
122
  when :track
120
- logger.info("Setting track to #{opt[:track]}")
123
+ UnitF::Log.info("Setting track to #{opt[:track]}")
121
124
  o.tag.genre = opt[:track]
125
+ when :year
126
+ UnitF::Log.info("Setting year to #{opt[:year]}")
127
+ o.tag.year = opt[:year]
122
128
  end
123
129
  end
124
- o.save || logger.error("Unable to save changes to #{file}")
130
+ o.save || UnitF::Log.error("Unable to save changes to #{file}")
125
131
  end
126
132
  end
@@ -77,7 +77,40 @@ module UnitF
77
77
  cover!(cover_path)
78
78
  end
79
79
 
80
+ def manual_auto_tags
81
+ UnitF::Log.info(auto_tag_path)
82
+ tags = {}
83
+ return {} unless ::File.exist?(auto_tag_path)
84
+ ::File.read(auto_tag_path).each_line do |line|
85
+ line.chomp!
86
+ UnitF::Log.info(line)
87
+ tag, value = line.split(/\s*=\s*/)
88
+ tags[tag.to_sym] = value
89
+ end
90
+ tags
91
+ rescue
92
+ {}
93
+ end
94
+
95
+ def auto_tags
96
+ manual_tags = manual_auto_tags
97
+ tags = {}
98
+
99
+ tags[:title] = ::File.basename(realpath.to_path)
100
+ track = tags[:title].match(/^\s*\d+/).to_s.to_i
101
+ tags[:title].gsub!(/\.\w+$/, '')
102
+ tags[:title].gsub!(/^\d*\s*(-|\.)*\s*/, '')
103
+ path_parts = realpath.dirname.to_path.split('/')
104
+ tags[:album] = path_parts[-1]
105
+ tags[:artist] = path_parts[-2]
106
+
107
+ tags.merge(manual_auto_tags)
108
+ end
109
+
80
110
  def auto_tag!
111
+ UnitF::Log.info("Auto tagging #{to_s}")
112
+ manual_auto_tags
113
+
81
114
  title = ::File.basename(realpath.to_path)
82
115
 
83
116
  # 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.6"
5
+ VERSION = "0.1.8"
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.6
4
+ version: 0.1.8
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-04 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
@@ -42,7 +42,7 @@ description: Audio File Tagging
42
42
  email:
43
43
  - mwb@unitf.net
44
44
  executables:
45
- - rtag
45
+ - tag
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
@@ -59,7 +59,7 @@ files:
59
59
  - bin/console
60
60
  - bin/setup
61
61
  - bin/test.rb
62
- - exe/rtag
62
+ - exe/tag
63
63
  - lib/unitf/tag.rb
64
64
  - lib/unitf/tag/export/exporter.rb
65
65
  - lib/unitf/tag/file.rb
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.2.32
96
+ rubygems_version: 3.3.26
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Audio File Tagging