unitf-tag 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd3119525797c4f3343cfbd7bd9228f75e47fae37d1eb2eea927a1d11c73819d
4
+ data.tar.gz: fe80b8b243dc3416c27fc31ec4b89cbe37891914e24a748d5e7827d5d0101af3
5
+ SHA512:
6
+ metadata.gz: 49a9d9a21aed7678da48f39f97a8c90283c818094dd6247a45f8425939e7641bac26c0698d3ba8d5fa3615f4a7b793e57b7fb7236a9d55909038482c99d89e75
7
+ data.tar.gz: 1afd544df883c40dd04fe37703c278df76e3064809c2d7a6b968ef43cd8545e4927097d8f78926c6147df24b9844d04ae24712a5fc346171e17f3a1376bee12b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ Layout/EmptyLineAfterGuardClause:
2
+ Enabled: false
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false
9
+
@@ -0,0 +1,52 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+ // for the documentation about the tasks.json format
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "label": "build-project",
8
+ "type": "shell",
9
+ "group": {
10
+ "kind": "build",
11
+ "isDefault": true
12
+ },
13
+ "options": {
14
+ "cwd": "${workspaceFolder}",
15
+ },
16
+ "presentation": {
17
+ "clear": true
18
+ },
19
+ "command": "bundle exec ruby bin/test.rb"
20
+ },
21
+ {
22
+ "label": "test-project",
23
+ "type": "shell",
24
+ "presentation": {
25
+ "clear": true
26
+ },
27
+ "group": {
28
+ "kind": "test",
29
+ "isDefault": true
30
+ },
31
+ "command": "bundle exec rspec ${workspaceRoot}"
32
+ },
33
+ {
34
+ "label": "lint-project",
35
+ "type": "shell",
36
+ "presentation": {
37
+ "clear": true
38
+ },
39
+ "command": "/usr/bin/env rubocop ${workspaceRoot}",
40
+ "problemMatcher": []
41
+ },
42
+ {
43
+ "label": "lint-file",
44
+ "type": "shell",
45
+ "presentation": {
46
+ "clear": true
47
+ },
48
+ "command": "/usr/bin/env rubocop ${file}",
49
+ "problemMatcher": []
50
+ }
51
+ ]
52
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mwb@unitf.net. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in unitf-tag.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Matt Baron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Unitf::Tag
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/unitf/tag`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'unitf-tag'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install unitf-tag
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unitf-tag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/unitf-tag/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Unitf::Tag project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/unitf-tag/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "unitf/tag"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/test.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'optparse'
2
+
3
+ require 'unitf/tag'
4
+
5
+ file_str = '/Users/mbaron/tag/music/fIREHOSE3/Sometimes'
6
+ file = UnitF::Tag::File.new(file_str)
7
+
8
+ puts file.to_s
data/exe/rtag ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'logger'
6
+ require 'optparse'
7
+ require 'unitf/tag'
8
+
9
+ logger = Logger.new($stdout)
10
+
11
+ actions = []
12
+ files = []
13
+ opt = {
14
+ :recursive => false,
15
+ :force => false
16
+ }
17
+
18
+ targets = OptionParser.new do |opts|
19
+ opts.on('-r', '--recursive', 'Auto Cover') do |item|
20
+ opt[:recursive] = true
21
+ end
22
+
23
+ opts.on('-d', '--dump', 'Dump Tags') do |item|
24
+ opt[:dump] = true
25
+ end
26
+
27
+ opts.on('--auto_cover', 'Auto Cover') do |item|
28
+ actions << :auto_cover
29
+ end
30
+
31
+ opts.on('--delete_cover', 'Delete Cover') do |item|
32
+ actions << :delete_cover
33
+ end
34
+
35
+ opts.on('--auto_tag', 'Auto Tag') do |item|
36
+ actions << :auto_tag
37
+ end
38
+
39
+ opts.on('-f', '--force', 'Force') do |arg|
40
+ opt[:force] = true
41
+ end
42
+
43
+ opts.on('--artist ARTIST', 'Artist') do |arg|
44
+ actions << :artist
45
+ opt[:artist] = arg
46
+ end
47
+
48
+ opts.on('--album ALBUM', 'Album') do |arg|
49
+ actions << :album
50
+ opt[:album] = arg
51
+ end
52
+
53
+ opts.on('--title TITLE', 'Song Title') do |arg|
54
+ actions << :title
55
+ opt[:title] = arg
56
+ end
57
+
58
+ opts.on('--genre GENRE', 'Genre') do |arg|
59
+ actions << :genre
60
+ opt[:genre] = arg
61
+ end
62
+ end.parse!
63
+
64
+ targets.each do |target|
65
+ files.concat(UnitF::Tag::process_target(target))
66
+ end
67
+
68
+ if files.size.zero? && actions.size.zero?
69
+ files = UnitF::Tag::find_files('.')
70
+ end
71
+
72
+ if files.size.zero?
73
+ logger.error('Cannot find any files to operate on')
74
+ end
75
+
76
+ if actions.size.zero?
77
+ files.each do |file|
78
+ file.open do |o|
79
+ o.print unless opt[:dump]
80
+ o.dump if opt[:dump]
81
+ end
82
+ end
83
+ exit 0
84
+ end
85
+
86
+ files.each do |file|
87
+ logger.info("Processing file: #{file}")
88
+ file.open do |o|
89
+ actions.each do |action|
90
+ case action
91
+ when :delete_cover
92
+ logger.info("Delete cover")
93
+ o.delete_cover!
94
+ when :auto_cover
95
+ unless o.cover?
96
+ logger.info("Auto Cover #{file.cover_path}")
97
+ begin
98
+ o.auto_cover!
99
+ rescue => e
100
+ logger.error("Failed to auto-cover file #{e}")
101
+ end
102
+ end
103
+ when :auto_tag
104
+ logger.info("Auto Tag")
105
+ o.auto_tag!
106
+ when :artist
107
+ logger.info("Setting artist to #{opt[:artist]}")
108
+ o.tag.artist = opt[:artist]
109
+ when :album
110
+ logger.info("Setting album to #{opt[:album]}")
111
+ o.tag.album = opt[:album]
112
+ when :title
113
+ logger.info("Setting title to #{opt[:title]}")
114
+ o.tag.title = opt[:title]
115
+ when :genre
116
+ logger.info("Setting genre to #{opt[:genre]}")
117
+ o.tag.genre = opt[:genre]
118
+ when :track
119
+ logger.info("Setting track to #{opt[:track]}")
120
+ o.tag.genre = opt[:track]
121
+ end
122
+ end
123
+ o.save
124
+ end
125
+ end
@@ -0,0 +1,94 @@
1
+ require 'find'
2
+ require 'taglib'
3
+ require 'pathname'
4
+ require 'logger'
5
+
6
+ module UnitF
7
+ module Tag
8
+ class File < Pathname
9
+ def initialize(file_path)
10
+ super(::File.absolute_path(file_path.to_s))
11
+ end
12
+
13
+ def tag
14
+ @file.tag
15
+ end
16
+
17
+ def print
18
+ puts "File : #{realpath}"
19
+ puts "Artist: #{tag.artist}"
20
+ puts "Album : #{tag.album}"
21
+ puts "Title : #{tag.title}"
22
+ puts "Track : #{tag.track}"
23
+ puts "Genre : #{tag.genre}"
24
+ puts "Year : #{tag.year}"
25
+ puts "Cover : #{cover?}"
26
+ puts "Stats : #{stats}"
27
+ puts
28
+ end
29
+
30
+ def cover_path
31
+ "#{dirname}/cover.jpg"
32
+ end
33
+
34
+ def auto_tag_path
35
+ "#{dirname}/.autotag"
36
+ end
37
+
38
+ def mp3?
39
+ extname.match(/\.mp3$/i)
40
+ end
41
+
42
+ def flac?
43
+ extname.match(/\.flac$/i)
44
+ end
45
+
46
+ def cover_available?
47
+ ::File.exist?(cover_path)
48
+ end
49
+
50
+ def auto_cover!
51
+ cover!(cover_path)
52
+ end
53
+
54
+ def auto_tag!
55
+ title = ::File.basename(realpath.to_path)
56
+
57
+ # This must come before gsubbing the title
58
+ track = title.match(/^\s*\d+/).to_s.to_i
59
+
60
+ title.gsub!(/\.\w+$/, '')
61
+ title.gsub!(/^\d*\s*(-|\.)*\s*/, '')
62
+
63
+ path_parts = realpath.dirname.to_path.split('/')
64
+ album = path_parts[-1]
65
+ artist = path_parts[-2]
66
+
67
+ tag.album = album
68
+ tag.artist = artist
69
+ tag.title = title
70
+ tag.track = track
71
+ self.album_artist = artist
72
+ end
73
+
74
+ def save
75
+ @file.save
76
+ end
77
+
78
+ def close
79
+ @file&.close
80
+ @file = nil
81
+ end
82
+
83
+ def open
84
+ object = if flac?
85
+ UnitF::Tag::FLAC.new(to_path)
86
+ elsif mp3?
87
+ UnitF::Tag::MP3.new(to_path)
88
+ end
89
+ yield(object) if block_given?
90
+ object&.close
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,52 @@
1
+ module UnitF
2
+ module Tag
3
+ class FLAC < UnitF::Tag::File
4
+ def initialize(file_path)
5
+ super(file_path)
6
+ @file = TagLib::FLAC::File.new(file_path)
7
+ end
8
+
9
+ def cover?
10
+ @file.picture_list.each do |pic|
11
+ return true if pic.type == TagLib::FLAC::Picture::FrontCover
12
+ end
13
+ false
14
+ end
15
+
16
+ def cover!(file_path)
17
+ pic = TagLib::FLAC::Picture.new
18
+ pic.type = TagLib::FLAC::Picture::FrontCover
19
+ pic.mime_type = "image/jpeg"
20
+ pic.description = "Front Cover"
21
+ pic.data = ::File.open(file_path, 'rb') { |f| f.read }
22
+ @file.add_picture(pic)
23
+ end
24
+
25
+ def delete_cover!
26
+ @file.remove_pictures
27
+ end
28
+
29
+ def album_artist=(artist)
30
+ @file.xiph_comment.add_field('ALBUM ARTIST', artist, true)
31
+ end
32
+
33
+ def stats
34
+ stats = @file.audio_properties
35
+ sprintf("%.1fkHz/%d-bit %dkbps", stats.sample_rate / 1000.to_f, stats.bits_per_sample, stats.bitrate)
36
+ end
37
+
38
+ def dump
39
+ puts "File: #{realpath}"
40
+ tag = @file.xiph_comment
41
+ tag.field_list_map.each_key do |key|
42
+ puts "#{key}: #{tag.field_list_map[key]}"
43
+ end
44
+
45
+ @file.picture_list.each do |pic|
46
+ puts "Picture: type=#{pic.type}, desc=#{pic.description}"
47
+ end
48
+ puts
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ module UnitF
2
+ module Tag
3
+ class MP3 < UnitF::Tag::File
4
+ def initialize(file_path)
5
+ super(file_path)
6
+ @file = TagLib::MPEG::File.new(file_path)
7
+ end
8
+
9
+ def stats
10
+ sprintf("%.1fkHz/%dkbps", @file.audio_properties.sample_rate / 1000.to_f, @file.audio_properties.bitrate)
11
+ end
12
+
13
+ def cover?
14
+ @file.id3v2_tag.frame_list('APIC').size > 0
15
+ end
16
+
17
+ def cover!(file_path)
18
+ apic = TagLib::ID3v2::AttachedPictureFrame.new
19
+ apic.mime_type = "image/jpeg"
20
+ apic.description = "Cover"
21
+ apic.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover
22
+ apic.picture = ::File.open(file_path, 'rb') { |f| f.read }
23
+ @file.id3v2_tag.add_frame(apic)
24
+ end
25
+
26
+ def delete_cover!
27
+ @file.id3v2_tag.remove_frames('APIC')
28
+ end
29
+
30
+ def album_artist=(artist)
31
+ @file.id3v2_tag.remove_frames('TPE2')
32
+ frame = TagLib::ID3v2::TextIdentificationFrame.new("TPE2", TagLib::String::UTF8)
33
+ frame.text = artist
34
+ @file.id3v2_tag.add_frame(frame)
35
+ end
36
+
37
+ def dump
38
+ puts "File: #{realpath}"
39
+ tag = @file.id3v2_tag
40
+ tag.frame_list.each do |frame|
41
+ next unless frame.is_a?(TagLib::ID3v2::TextIdentificationFrame)
42
+ puts "#{frame.frame_id}: #{tag.frame_list(frame.frame_id).first}"
43
+ end
44
+ puts
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitf
4
+ module Tag
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/unitf/tag.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tag/version'
4
+ require_relative 'tag/file'
5
+ require_relative 'tag/flac'
6
+ require_relative 'tag/mp3'
7
+
8
+ module UnitF
9
+ module Tag
10
+ class Error < StandardError; end
11
+ class MissingCover < Error; end
12
+
13
+ def self.logger
14
+ @logger ||= Logger.new($stdout)
15
+ end
16
+
17
+ def self.valid_file?(file_path)
18
+ ::File.file?(file_path) && file_path.match(/\.(flac|mp3)$/i)
19
+ end
20
+
21
+ def self.process_target(target)
22
+ if ::File.directory?(target)
23
+ find_files(target)
24
+ elsif valid_file?(target)
25
+ [UnitF::Tag::File.new(target)]
26
+ else
27
+ []
28
+ end
29
+ end
30
+
31
+ def self.find_files(root_path)
32
+ files = []
33
+ Find.find(root_path) do |file_path|
34
+ next unless valid_file?(file_path)
35
+ files << UnitF::Tag::File.new(file_path)
36
+ end
37
+ files
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitf
4
+ module Tagger
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/tag ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/local/bin/ruby
2
+
data/test.rb ADDED
@@ -0,0 +1,20 @@
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
data/unitf-tag.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/unitf/tag/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "unitf-tag"
7
+ spec.version = Unitf::Tag::VERSION
8
+ spec.authors = ["Matt Baron"]
9
+ spec.email = ["mwb@unitf.net"]
10
+
11
+ spec.summary = "Audio File Tagging"
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/mattbaron/unitf-tag"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = 'https://www.rubygems.org'
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/mattbaron/unitf-tag"
21
+ spec.metadata["changelog_uri"] = "https://github.com/mattbaron/unitf-tag/CHANGELOG.md"
22
+
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "taglib-ruby"
31
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unitf-tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Baron
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: taglib-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Audio File Tagging
28
+ email:
29
+ - mwb@unitf.net
30
+ executables:
31
+ - rtag
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".vscode/tasks.json"
39
+ - CHANGELOG.md
40
+ - CODE_OF_CONDUCT.md
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - bin/test.rb
48
+ - exe/rtag
49
+ - lib/unitf/tag.rb
50
+ - lib/unitf/tag/file.rb
51
+ - lib/unitf/tag/flac.rb
52
+ - lib/unitf/tag/mp3.rb
53
+ - lib/unitf/tag/version.rb
54
+ - lib/unitf/version.rb
55
+ - tag
56
+ - test.rb
57
+ - unitf-tag.gemspec
58
+ homepage: https://github.com/mattbaron/unitf-tag
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ allowed_push_host: https://www.rubygems.org
63
+ homepage_uri: https://github.com/mattbaron/unitf-tag
64
+ source_code_uri: https://github.com/mattbaron/unitf-tag
65
+ changelog_uri: https://github.com/mattbaron/unitf-tag/CHANGELOG.md
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.6.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.2.22
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Audio File Tagging
85
+ test_files: []