unitf-tag 0.1.7 → 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: da63e27abbe2ad5f02751954906494623640d52ebee71c99cdde24e0e5cc9b45
4
- data.tar.gz: b6c8833b6a6c692fa584ba68e058cc0aa69f29b192d8d26b52bfa2c31e080dbb
3
+ metadata.gz: 68404fe4f09503662b8fa2f52479ce65d14f5c9eea0d6928e99a10599c468be8
4
+ data.tar.gz: 398a8ea66bcfa0dcc33d3fafb1e51f6fcd305c4377644df6a3d5ad94f3786647
5
5
  SHA512:
6
- metadata.gz: 4e2bf3be1deb74914640c50e2fe3c424973742a48a0d006e889eae7b57b9cceb996897e1d431c02fe694fa2999a1f80fc161ef27fa1beab475f7d76e5eebd437
7
- data.tar.gz: da3d156c8dd3d507588d11e2eee893d24952ea31f611ac556010793442174f2a93b32f3b55e508d44a555b6125a7a2e799686962e12acbea2681af443980dd87
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/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
@@ -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.7"
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.7
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-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
@@ -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.22
96
+ rubygems_version: 3.3.26
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Audio File Tagging