unitf-tag 0.1.10 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cd6b6ef13a18bcf331971fcb6c93f5d3f093954e4f5881e864e794eef19ea84
4
- data.tar.gz: baab06a10e951d55341521b3bcadfdf7737ae94e34f6fa625e67df2eb5a73f6f
3
+ metadata.gz: 7b16a3b7f4448536620cf9bc5ac134c082a9bfd61a7bd57e685d254397d97412
4
+ data.tar.gz: 253ac7cc3eabd4e6a812c76588854aff868aac9dd422434a0fc0175a55adab0b
5
5
  SHA512:
6
- metadata.gz: 1883d756f5ec860097a4335e432855f12370c7dbce7a3f6c7b1ab3f3cf59cc51189235ca0c475719c1dafac2961d3c7cdf8388539323289c3842fdbf4869e6b4
7
- data.tar.gz: e909cca15e818791efa99c7c52bfd4689a1a8aa891c63d787a92fd653b2896d4c526d9340fd0fbc539dd7f6cbb0d345d2150e61243c196b3dfd8cebd572bd87d
6
+ metadata.gz: 58f21090b63069f22238a98a75b8545f6a2652428982025b562ef73ef80fdd7af54b363887c60be2f13f124dc0e33853d59e2e8778b533b600280e3624ca3848
7
+ data.tar.gz: 013d2107a8fe2ce6b68b15f6a5d490cda5a4b2b90d591641c062519172f4c63874834fc30d2f68bbf81ae330622849e83aaf034db31045ea8b530778a954581c
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/tag --dump /Users/mbaron/Desktop/sb/*"
20
20
  },
21
21
  {
22
22
  "label": "test-project",
data/exe/tag CHANGED
@@ -13,6 +13,8 @@ actions = []
13
13
  files = []
14
14
  opt = {}
15
15
 
16
+ no_args = ARGV.size.zero?
17
+
16
18
  targets = OptionParser.new do |opts|
17
19
  opts.on('-r', '--recursive', 'Auto Cover') do
18
20
  opt[:recursive] = true
@@ -34,6 +36,12 @@ targets = OptionParser.new do |opts|
34
36
  opt[:format] = :line
35
37
  end
36
38
 
39
+ opts.on('--cover COVER', 'Cover') do |arg|
40
+ actions << :cover
41
+ raise "Invalid cover file #{arg}" unless ::File.exist?(arg) && arg.downcase.end_with?('.jpg')
42
+ opt[:cover] = arg
43
+ end
44
+
37
45
  opts.on('--auto_cover', 'Auto Cover') do
38
46
  actions << :auto_cover
39
47
  end
@@ -74,8 +82,15 @@ targets = OptionParser.new do |opts|
74
82
  actions << :genre
75
83
  opt[:genre] = arg
76
84
  end
85
+
86
+ opts.on('--track TRACK', 'Song Track') do |arg|
87
+ actions << :track
88
+ opt[:track] = arg.to_i
89
+ end
77
90
  end.parse!
78
91
 
92
+ targets = Dir.glob('*') if no_args
93
+
79
94
  files = UnitF::Tag::FileSet.new(targets)
80
95
 
81
96
  if files.size.zero?
@@ -92,6 +107,9 @@ files.each do |file|
92
107
  file.open do |o|
93
108
  actions.each do |action|
94
109
  case action
110
+ when :cover
111
+ UnitF::Log.info("Cover #{opt[:cover]}")
112
+ o.cover!(opt[:cover])
95
113
  when :delete_cover
96
114
  UnitF::Log.info('Delete cover')
97
115
  o.delete_cover!
@@ -105,7 +123,7 @@ files.each do |file|
105
123
  end
106
124
  end
107
125
  when :auto_tag
108
- UnitF::Log.info('Auto Tag')
126
+ UnitF::Log.info("Auto Tag #{file}")
109
127
  o.auto_tag!
110
128
  when :artist
111
129
  UnitF::Log.info("Setting artist to #{opt[:artist]}")
@@ -121,7 +139,7 @@ files.each do |file|
121
139
  o.tag.genre = opt[:genre]
122
140
  when :track
123
141
  UnitF::Log.info("Setting track to #{opt[:track]}")
124
- o.tag.genre = opt[:track]
142
+ o.tag.track = opt[:track]
125
143
  when :year
126
144
  UnitF::Log.info("Setting year to #{opt[:year]}")
127
145
  o.tag.year = opt[:year]
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'logger'
6
+ require 'optparse'
7
+ require 'unitf/tag'
8
+ require 'unitf/logging'
9
+
10
+ UnitF::Log.to_console
11
+
12
+ files = UnitF::Tag::FileSet.new(ARGV)
13
+
14
+ files.each do |file|
15
+ puts "File: #{file}"
16
+ puts "Tags: #{file.auto_tags}"
17
+ end
@@ -58,7 +58,7 @@ module UnitF
58
58
  end
59
59
 
60
60
  def auto_tag_path
61
- "#{dirname}/.autotag"
61
+ "#{dirname}/.autotag.json"
62
62
  end
63
63
 
64
64
  def mp3?
@@ -77,23 +77,21 @@ module UnitF
77
77
  cover!(cover_path) if cover_available?
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
80
+ # def auto_tag_override
81
+ # tags = {}
82
+ # return {} unless ::File.exist?(auto_tag_path)
83
+ # ::File.read(auto_tag_path).each_line do |line|
84
+ # line.strip!
85
+ # # UnitF::Log.info(line)
86
+ # tag, value = line.split(/\s*=\s*/)
87
+ # tags[tag.to_sym] = value
88
+ # end
89
+ # tags
90
+ # rescue
91
+ # {}
92
+ # end
94
93
 
95
94
  def auto_tags
96
- manual_tags = manual_auto_tags
97
95
  tags = {}
98
96
 
99
97
  tags[:title] = ::File.basename(realpath.to_path)
@@ -104,30 +102,20 @@ module UnitF
104
102
  tags[:album] = path_parts[-1]
105
103
  tags[:artist] = path_parts[-2]
106
104
 
107
- tags.merge(manual_auto_tags)
105
+ begin
106
+ tags.merge!(JSON.parse(::File.read(auto_tag_path), symbolize_names: true))
107
+ rescue; end
108
+
109
+ tags
108
110
  end
109
111
 
110
112
  def auto_tag!
111
- UnitF::Log.info("Auto tagging #{to_s}")
112
- manual_auto_tags
113
-
114
- title = ::File.basename(realpath.to_path)
115
-
116
- # This must come before gsubbing the title
117
- track = title.match(/^\s*\d+/).to_s.to_i
118
-
119
- title.gsub!(/\.\w+$/, '')
120
- title.gsub!(/^\d*\s*(-|\.)*\s*/, '')
121
-
122
- path_parts = realpath.dirname.to_path.split('/')
123
- album = path_parts[-1]
124
- artist = path_parts[-2]
125
-
126
- tag.album = album
127
- tag.artist = artist
128
- tag.title = title
129
- tag.track = track
130
- self.album_artist = artist
113
+ tags = auto_tags
114
+ tag.album = tags[:album]
115
+ tag.artist = tags[:artist]
116
+ tag.title = tags[:title]
117
+ tag.track = tags[:track] unless tags[:track].nil?
118
+ self.album_artist = tags[:artist]
131
119
  end
132
120
 
133
121
  def save
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = "0.1.10"
5
+ VERSION = "0.1.16"
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.10
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Baron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-11 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby
@@ -43,6 +43,7 @@ email:
43
43
  - mwb@unitf.net
44
44
  executables:
45
45
  - tag
46
+ - unitf-autotags
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -60,6 +61,7 @@ files:
60
61
  - bin/setup
61
62
  - bin/test.rb
62
63
  - exe/tag
64
+ - exe/unitf-autotags
63
65
  - lib/unitf/tag.rb
64
66
  - lib/unitf/tag/export/exporter.rb
65
67
  - lib/unitf/tag/file.rb