unitf-tag 0.2.0 → 0.2.3

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: 0e8a3abd8e593009ee730ed4ee98c85f9f0b5665cdccf7ac1ea68b0f29e793a6
4
- data.tar.gz: 2b62f8700524ba32f9961b14c129869a98b4e0fbf304c05173f9e059820d8bb3
3
+ metadata.gz: 19333251d43535450349e9f570926c4decfe95e01c0196c579b086d154bf9760
4
+ data.tar.gz: 40de5a30bd06cf0c4c7d3ac781f3e56eae23681ebad02256774791a9ee2b99b0
5
5
  SHA512:
6
- metadata.gz: d5a1dd21d9cddb72642a99e8d0f1274f6e95a3fc76e80d9bb71838c6addc201814ac3dd0ff1d38482af6464ab37eddd5cd643d70240bf7fdf5fba80866d9c156
7
- data.tar.gz: 6e7d036234644964322c41dd0dcc4d8e9982c76c6abc4dd430c28a88431f635194da76826c153dcd249b6c0e4a0d26c2e2892b74f75f8063d7ece32fdb99cca7
6
+ metadata.gz: 0fc46a438f35b659a88b18f335f1392e3fa4563619d0c1c084bc1e6aa6d158d03305e1b5dd4b137bc185b8aa0b52e56da9da8c07dc92e112fd2f0f666da622ae
7
+ data.tar.gz: cfe8bab25e0731692695f6ab316280551b9cd22daa0ec5a0a5f45746f7eed80e99e1950aa0f074879f07401a0822024e48f889c75a0a3ebda79a5a8a0db06f11
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # UnitF::Tag
2
2
 
3
+ ## v0.2.3
4
+ - Add `--auto_track` option to run `UnitF::Tag.auto_track`
5
+
6
+ ## v0.2.2
7
+ - Change `UnitF::Tag.auto_track` signature
8
+
9
+ ## v0.2.1
10
+ - Add `UnitF::Tag.auto_track`
11
+ - Add `UnitF::Tag.open`
12
+
3
13
  ## v0.2.0
4
14
  - `UnitF::Tag::File` no longer inherits anything]
5
15
  - Spec Tests
data/bin/test.rb CHANGED
@@ -4,7 +4,4 @@ require 'unitf/tag'
4
4
 
5
5
  UnitF::Log.to_console
6
6
 
7
- UnitF::Tag.update('test-data/song.mp3') do |file|
8
- puts "FILE: #{file}"
9
- file.tag.artist = "Update #{Time.now.to_s}"
10
- end
7
+ UnitF::Tag.auto_track(dir: '/Users/mbaron/music2/WFMU/BJ/2025')
data/exe/tag CHANGED
@@ -13,6 +13,8 @@ actions = []
13
13
  opt = {}
14
14
  properties = {}
15
15
 
16
+ auto_track = []
17
+
16
18
  no_args = ARGV.empty?
17
19
 
18
20
  targets = OptionParser.new do |opts|
@@ -58,6 +60,10 @@ targets = OptionParser.new do |opts|
58
60
  actions << :auto_tags
59
61
  end
60
62
 
63
+ opts.on('--auto_track DIRECTORY', 'Auto Track') do |dir|
64
+ auto_track << dir
65
+ end
66
+
61
67
  opts.on('-f', '--force', 'Force') do
62
68
  opt[:force] = true
63
69
  end
@@ -87,11 +93,16 @@ targets = OptionParser.new do |opts|
87
93
  end
88
94
  end.parse!
89
95
 
90
- targets = Dir.glob('*') if no_args
96
+ auto_track.each do |dir|
97
+ UnitF::Tag.auto_track(dir)
98
+ rescue StandardError => e
99
+ UnitF::Log.warn(e.message)
100
+ end
91
101
 
102
+ targets = Dir.glob('*') if no_args
92
103
  files = UnitF::Tag::FileSet.new(targets)
93
104
 
94
- UnitF::Log.error('Cannot find any files to operate on') if files.empty?
105
+ exit(0) if files.empty?
95
106
 
96
107
  if actions.empty? && properties.empty?
97
108
  UnitF::Tag.list(files, format: opt[:format])
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unitf
4
4
  module Tag
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.3'
6
6
  end
7
7
  end
data/lib/unitf/tag.rb CHANGED
@@ -19,6 +19,12 @@ module UnitF
19
19
  end
20
20
  end
21
21
 
22
+ def open(file_path)
23
+ UnitF::Tag::File.new(file_path).open do |file|
24
+ yield file
25
+ end
26
+ end
27
+
22
28
  def list(files, format: :json)
23
29
  buff = []
24
30
  files.each do |file|
@@ -35,9 +41,34 @@ module UnitF
35
41
  end
36
42
  puts JSON.pretty_generate(buff) if format == :json
37
43
  end
44
+
45
+ def auto_track(dir)
46
+ raise Error, "Invalid directory #{dir}" unless ::Dir.exist?(dir)
47
+
48
+ UnitF::Log.info("Auto track #{dir}")
49
+ track = 1
50
+
51
+ Dir.glob("#{dir}/*.mp3").sort.each do |file_path|
52
+ if ::File.basename(file_path).match?(/^\d+(\s|\.|-)/)
53
+ UnitF::Log.warn("Skipping #{file_path}")
54
+ next
55
+ end
56
+
57
+ UnitF::Tag.open(file_path) do |file|
58
+ if file.tag.track != track
59
+ UnitF::Log.info("Setting track to #{track} #{file_path}")
60
+ file.tag.track = track
61
+ file.save
62
+ end
63
+ end
64
+
65
+ track += 1
66
+ end
67
+ end
38
68
  end
39
69
 
40
70
  class Error < StandardError; end
71
+
41
72
  class MissingCover < Error; end
42
73
  end
43
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitf-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Baron
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-04 00:00:00.000000000 Z
10
+ date: 2025-04-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: logger