track_list 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -8
- data/CHANGELOG.md +23 -12
- data/Gemfile +5 -4
- data/Gemfile.lock +31 -8
- data/LICENSE.txt +21 -21
- data/README.md +82 -58
- data/Rakefile +2 -2
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/bin/tracklist +42 -33
- data/lib/track_list/directory_parser.rb +51 -31
- data/lib/track_list/environment.rb +15 -0
- data/lib/track_list/template_parser.rb +45 -0
- data/lib/track_list/time_converter.rb +29 -21
- data/lib/track_list/track_parser.rb +65 -27
- data/lib/track_list/version.rb +3 -3
- data/lib/track_list.rb +12 -29
- data/track_list.gemspec +34 -34
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68768df5d84a827b02666436938a4f8f1a55f1bce90ede8a0f9fd339b0ea159b
|
4
|
+
data.tar.gz: ea4ed055dd77e1412e06b68ed660456fdc2ca20e6eeccbe34db9b5d8c84d3ea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5146ca78561029af6bf9f5308704194aec17fbd6e7586c0eb3de36545a80046a14e1f188541678ee4cccb7f68834e58376430c35636fe62c9574a8dac4603df7
|
7
|
+
data.tar.gz: 03ce59b3a00ae00a4bb0581764aa63b06106b5da455d6de59dce2b3ad2ec413f58ae9eea4a672b79a4a9eca2eef3d61bca86454f8c18f4d2e633acbfa30d0e92
|
data/.gitignore
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
.idea
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
-
# Changelog
|
2
|
-
All notable changes to this project will be documented in this file.
|
3
|
-
|
4
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
-
|
7
|
-
## [0.
|
8
|
-
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.2.0] - 2019-08-09
|
8
|
+
- Added custom templating so a user can define what is output to their tracklist.
|
9
|
+
- TemplateParser class that helps with reading/writing to a config/template file.
|
10
|
+
- Commented code with RDoc.
|
11
|
+
- Cleaned up codebase more.
|
12
|
+
|
13
|
+
## [0.1.1] - 2019-08-08
|
14
|
+
### Fixed
|
15
|
+
- Missing ARGV argument no longer throws a fatal error but shows a helpful message instead.
|
16
|
+
- Cleaned up codebase a bit.
|
17
|
+
|
18
|
+
## [0.1.0] - 2019-08-08
|
19
|
+
### Added
|
20
|
+
- Separation of concerns compared to old codebase. Current codebase is cleaner.
|
21
|
+
- TrackParser class that parses a single track.
|
22
|
+
- DirectoryParser class that parses a directory, using TrackParser.
|
23
|
+
- TimeConverter class that puts seconds into hour:minute:seconds for easy readability on track lengths.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
track_list (0.
|
5
|
-
taglib-ruby (~>
|
4
|
+
track_list (0.3.0)
|
5
|
+
taglib-ruby (~> 1.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
10
|
+
ast (2.4.2)
|
11
|
+
json (2.6.2)
|
12
|
+
parallel (1.22.1)
|
13
|
+
parser (3.1.2.0)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.1.1)
|
16
|
+
rake (13.0.6)
|
17
|
+
regexp_parser (2.5.0)
|
18
|
+
rexml (3.2.5)
|
19
|
+
rubocop (1.32.0)
|
20
|
+
json (~> 2.3)
|
21
|
+
parallel (~> 1.10)
|
22
|
+
parser (>= 3.1.0.0)
|
23
|
+
rainbow (>= 2.2.2, < 4.0)
|
24
|
+
regexp_parser (>= 1.8, < 3.0)
|
25
|
+
rexml (>= 3.2.5, < 4.0)
|
26
|
+
rubocop-ast (>= 1.19.1, < 2.0)
|
27
|
+
ruby-progressbar (~> 1.7)
|
28
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
29
|
+
rubocop-ast (1.19.1)
|
30
|
+
parser (>= 3.1.1.0)
|
31
|
+
ruby-progressbar (1.11.0)
|
32
|
+
taglib-ruby (1.1.2)
|
33
|
+
unicode-display_width (2.2.0)
|
12
34
|
|
13
35
|
PLATFORMS
|
14
|
-
|
36
|
+
x86_64-linux
|
15
37
|
|
16
38
|
DEPENDENCIES
|
17
|
-
bundler (
|
18
|
-
rake (~>
|
39
|
+
bundler (>= 2.2)
|
40
|
+
rake (~> 13.0)
|
41
|
+
rubocop
|
19
42
|
taglib-ruby
|
20
43
|
track_list!
|
21
44
|
|
22
45
|
BUNDLED WITH
|
23
|
-
2.
|
46
|
+
2.2.3
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Domenic Fiore
|
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.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Domenic Fiore
|
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
CHANGED
@@ -1,58 +1,82 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
```
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
1
|
+
# Track List
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/track_list.svg)](https://badge.fury.io/rb/track_list)
|
4
|
+
|
5
|
+
This program aims to provide an easy way to get a track list for an album in your terminal, or you could use it in your own program if you wish. Define your own custom template to output your track lists or use the predefined one. The predefined one is below. If you'd like to customize this output, scroll down to Configuration.
|
6
|
+
|
7
|
+
## Sample Output
|
8
|
+
```
|
9
|
+
1. Tellin' Lies (0:03:59)
|
10
|
+
2. Thick as Thieves (0:03:15)
|
11
|
+
3. Lookers (0:03:37)
|
12
|
+
4. Midwestern States (0:03:27)
|
13
|
+
5. Charlie's Army (0:02:31)
|
14
|
+
6. House on Fire (0:03:37)
|
15
|
+
7. Black Mass (0:02:52)
|
16
|
+
8. Boy Blue (0:03:20)
|
17
|
+
9. Bad Catholics (0:02:52)
|
18
|
+
10. Your Wild Years (0:03:54)
|
19
|
+
11. The Bars (0:04:11)
|
20
|
+
12. After the Party (0:03:50)
|
21
|
+
13. Livin' Ain't Easy (0:03:26)
|
22
|
+
```
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
First, install [TagLib](https://taglib.org/).
|
27
|
+
|
28
|
+
Homebrew: `brew install taglib`
|
29
|
+
|
30
|
+
Ubuntu/Debian: `sudo apt install libtag1-dev`
|
31
|
+
|
32
|
+
Arch: `sudo pacman -S taglib`
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'track_list'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
|
46
|
+
$ gem install track_list
|
47
|
+
|
48
|
+
## Configuration
|
49
|
+
|
50
|
+
You can define custom output for your track list. On first run of the program, the program will create a `settings.yaml` file in the `$HOME/.config/track_list` directory.
|
51
|
+
|
52
|
+
If you would like to change this location, set the environment variable `TRACKLIST_CONFIG` to where you'd like the file.
|
53
|
+
|
54
|
+
The default output is as follows:
|
55
|
+
|
56
|
+
`output: "%TRACK%. %TITLE% (%LENGTH%)"`
|
57
|
+
|
58
|
+
You can change this string with the following tags to format it the way you want it:
|
59
|
+
- `%TRACK%` - The track number of a given audio file.
|
60
|
+
- `%TITLE%` - The title tag of a given audio file.
|
61
|
+
- `%LENGTH%` - The length of a given audio file in `[hours:minutes:seconds]`
|
62
|
+
- `%LENGTH_IN_MILLISECONDS%` - The length of a given audio file in milliseconds.
|
63
|
+
- `%ARTIST%` - The artist tag of a given audio file.
|
64
|
+
- `%ALBUM%` - The album tag of a given audio file.
|
65
|
+
- `%YEAR%` - The year tag of a given audio file.
|
66
|
+
- `%GENRE%` - The genre tag of a given audio file.
|
67
|
+
- `%COMMENT%` - The comment tag of a given audio file.
|
68
|
+
|
69
|
+
If a tag does not exist, you should see an empty space in the output. If you are getting some sort of error, please file an issue.
|
70
|
+
|
71
|
+
## Usage
|
72
|
+
|
73
|
+
`tracklist <album directory>`
|
74
|
+
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/DomenicF/track_list/issues.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :spec
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "track_list"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "track_list"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +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
|
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/tracklist
CHANGED
@@ -1,33 +1,42 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "track_list"
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
opts
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "track_list"
|
4
|
+
require 'track_list/template_parser'
|
5
|
+
require 'getoptlong'
|
6
|
+
|
7
|
+
opts = GetoptLong.new(
|
8
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
|
9
|
+
)
|
10
|
+
|
11
|
+
|
12
|
+
opts.each do |opt, arg|
|
13
|
+
case opt
|
14
|
+
when '--help'
|
15
|
+
puts <<-EOF
|
16
|
+
Usage: tracklist <album-directory>
|
17
|
+
e.g. tracklist "Music/The Menzingers/After the Party"
|
18
|
+
|
19
|
+
-h, --help:
|
20
|
+
show help
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if ARGV.length != 1
|
26
|
+
puts "Missing album directory (try --help)"
|
27
|
+
exit 0
|
28
|
+
end
|
29
|
+
|
30
|
+
dir = TrackList::DirectoryParser.new(ARGV[0])
|
31
|
+
|
32
|
+
template_parser = TrackList::TemplateParser.new
|
33
|
+
|
34
|
+
# Let's create a default config file if one does not exist.
|
35
|
+
unless template_parser.config_exists?
|
36
|
+
template_parser.create_default_config
|
37
|
+
end
|
38
|
+
|
39
|
+
# Loop over each track and output to terminal.
|
40
|
+
dir.parse.each do |track|
|
41
|
+
puts track.parse if track.parse.is_a? String
|
42
|
+
end
|
@@ -1,31 +1,51 @@
|
|
1
|
-
require 'track_list/track_parser'
|
2
|
-
|
3
|
-
module TrackList
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
require 'track_list/track_parser'
|
2
|
+
|
3
|
+
module TrackList
|
4
|
+
|
5
|
+
# This class is a helper to parse through an entire directory of tracks
|
6
|
+
# and return an array of parsed, formatted tracks.
|
7
|
+
|
8
|
+
class DirectoryParser
|
9
|
+
|
10
|
+
# When initializing the class, pass in a directory with audio files
|
11
|
+
# to be parsed.
|
12
|
+
#
|
13
|
+
# @param [String] dir The directory to be parsed.
|
14
|
+
|
15
|
+
def initialize(dir)
|
16
|
+
@dir = dir
|
17
|
+
end
|
18
|
+
|
19
|
+
# This method gets a list of files to be parsed.
|
20
|
+
#
|
21
|
+
# @return [Array] Files to be parsed.
|
22
|
+
|
23
|
+
def list
|
24
|
+
files = []
|
25
|
+
Dir.foreach(@dir) do |file|
|
26
|
+
files.push(@dir + '/' + file)
|
27
|
+
end
|
28
|
+
return files
|
29
|
+
end
|
30
|
+
|
31
|
+
# This method does the bulk of the work. It loops over each of the files we
|
32
|
+
# got in +self.list+ and returns an array of +TrackList::TrackParser+ objects
|
33
|
+
# to be looped over elsewhere.
|
34
|
+
#
|
35
|
+
# @return [Array] of +TrackList::TrackParser+ objects.
|
36
|
+
|
37
|
+
def parse
|
38
|
+
files = self.list.sort
|
39
|
+
parsed_tracks = []
|
40
|
+
files.each do |filename, index|
|
41
|
+
track = TrackList::TrackParser.new(filename)
|
42
|
+
if track != nil || track != ''
|
43
|
+
parsed_tracks.push(track)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return parsed_tracks
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TrackList
|
2
|
+
class Environment
|
3
|
+
def initialize
|
4
|
+
if ENV.has_value?("TRACKLIST_CONFIG")
|
5
|
+
@config_path = ENV["TRACKLIST_CONFIG"]
|
6
|
+
else
|
7
|
+
@config_path = Dir.home() + '/.config/track_list/settings.yaml'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_config_path
|
12
|
+
@config_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'yaml'
|
3
|
+
require 'track_list/environment'
|
4
|
+
|
5
|
+
module TrackList
|
6
|
+
|
7
|
+
# A helper class to read/write a config file.
|
8
|
+
|
9
|
+
class TemplateParser
|
10
|
+
|
11
|
+
# Pass in a file path to read/write the config file.
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
environment = Environment.new
|
15
|
+
@config_path = environment.get_config_path
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return the config file in a Ruby-readable format.
|
19
|
+
|
20
|
+
def load
|
21
|
+
YAML.load(File.open(File.expand_path(@config_path)))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Check if the config file already exists.
|
25
|
+
|
26
|
+
def config_exists?
|
27
|
+
if File.exist?(File.expand_path(@config_path))
|
28
|
+
true
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create a default config file with some basic settings.
|
35
|
+
|
36
|
+
def create_default_config
|
37
|
+
config = { "output" => "%TRACK%. %TITLE% (%LENGTH%)" }
|
38
|
+
FileUtils.mkdir_p File.dirname(@config_path)
|
39
|
+
out_file = File.new(File.expand_path(@config_path), 'w')
|
40
|
+
out_file.puts(config.to_yaml)
|
41
|
+
out_file.close
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -1,22 +1,30 @@
|
|
1
|
-
module TrackList
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
module TrackList
|
2
|
+
|
3
|
+
# A helper class to convert an audio track's length in seconds to a more readable format.
|
4
|
+
|
5
|
+
class TimeConverter
|
6
|
+
|
7
|
+
# Pass in an integer of seconds to this class.
|
8
|
+
|
9
|
+
def initialize(time)
|
10
|
+
@time = time
|
11
|
+
end
|
12
|
+
|
13
|
+
# This method formats the time into a readable format.
|
14
|
+
# See: https://www.codethought.com/2010/01/seconds-minutes-hours-converting-time-units-in-ruby/
|
15
|
+
|
16
|
+
def format_time
|
17
|
+
# Find the seconds.
|
18
|
+
seconds = @time % 60
|
19
|
+
|
20
|
+
# Find the minutes.
|
21
|
+
minutes = (@time / 60) % 60
|
22
|
+
|
23
|
+
# Find the hours.
|
24
|
+
hours = (@time / 3600)
|
25
|
+
|
26
|
+
# Format the time.
|
27
|
+
return hours.to_s + ":" + format("%02d", minutes.to_s) + ":" + format("%02d", seconds.to_s)
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
@@ -1,28 +1,66 @@
|
|
1
|
-
require 'taglib'
|
2
|
-
require 'track_list/
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
1
|
+
require 'taglib'
|
2
|
+
require 'track_list/environment'
|
3
|
+
require 'track_list/time_converter'
|
4
|
+
require 'track_list/template_parser'
|
5
|
+
|
6
|
+
module TrackList
|
7
|
+
##
|
8
|
+
# The purpose of this class is to parse a single track and return a formatted
|
9
|
+
# string.
|
10
|
+
|
11
|
+
class TrackParser
|
12
|
+
|
13
|
+
##
|
14
|
+
# When initializing the class, you must pass in a file path to the +track+
|
15
|
+
# you want parsed.
|
16
|
+
#
|
17
|
+
# @param [String] track The track to be parsed.
|
18
|
+
|
19
|
+
def initialize(track)
|
20
|
+
@track = track
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# The bulk of the work is done in this method. Calling this method returns
|
25
|
+
# a parsed track in a formatted string.
|
26
|
+
#
|
27
|
+
# @return [String] if valid audio file.
|
28
|
+
|
29
|
+
def parse
|
30
|
+
TagLib::FileRef.open(@track) do |fileref|
|
31
|
+
unless fileref.null?
|
32
|
+
tag = fileref.tag
|
33
|
+
properties = fileref.audio_properties
|
34
|
+
time_conversion = TrackList::TimeConverter.new(properties.length_in_seconds)
|
35
|
+
length = time_conversion.format_time
|
36
|
+
|
37
|
+
template_parser = TrackList::TemplateParser.new
|
38
|
+
template = template_parser.load
|
39
|
+
|
40
|
+
template_strings = {
|
41
|
+
'%TRACK%' => tag.track.to_s,
|
42
|
+
'%TITLE%' => tag.title,
|
43
|
+
'%LENGTH%' => length,
|
44
|
+
'%LENGTH_IN_MILLISECONDS%' => properties.length_in_milliseconds.to_s,
|
45
|
+
'%ARTIST%' => tag.artist,
|
46
|
+
'%ALBUM%' => tag.album,
|
47
|
+
'%YEAR%' => tag.year.to_s,
|
48
|
+
'%GENRE%' => tag.genre,
|
49
|
+
'%COMMENT%' => tag.comment
|
50
|
+
}
|
51
|
+
|
52
|
+
parsed_string = ''
|
53
|
+
|
54
|
+
template_strings.each do |key, val|
|
55
|
+
if template['output'].include? key
|
56
|
+
parsed_string = template['output'].gsub!(key, val)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
return parsed_string
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
28
66
|
end
|
data/lib/track_list/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module TrackList
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module TrackList
|
2
|
+
VERSION = "0.3.0"
|
3
|
+
end
|
data/lib/track_list.rb
CHANGED
@@ -1,29 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require 'track_list/track_parser'
|
3
|
-
require 'track_list/directory_parser'
|
4
|
-
require 'track_list/time_converter'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
dir.parse.each do |track|
|
14
|
-
puts track.parse if track.parse.is_a? String
|
15
|
-
end
|
16
|
-
|
17
|
-
# dir_file_list = dir.list
|
18
|
-
|
19
|
-
# tracks = []
|
20
|
-
|
21
|
-
# dir_file_list.each do |n|
|
22
|
-
# tracks.push(TrackList::TrackParser.new(n))
|
23
|
-
# end
|
24
|
-
|
25
|
-
# tracks.each do |track|
|
26
|
-
# #p track.parse
|
27
|
-
# end
|
28
|
-
|
29
|
-
# dir.parse
|
1
|
+
require 'track_list/version'
|
2
|
+
require 'track_list/track_parser'
|
3
|
+
require 'track_list/directory_parser'
|
4
|
+
require 'track_list/time_converter'
|
5
|
+
require 'track_list/template_parser'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# This module defines the base of our program.
|
9
|
+
|
10
|
+
module TrackList
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
data/track_list.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
lib = File.expand_path("lib", __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "track_list/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "track_list"
|
7
|
-
spec.version = TrackList::VERSION
|
8
|
-
spec.authors = ["Domenic Fiore"]
|
9
|
-
spec.email = ["domenicfiore@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = %q{Get the tracklist of a directory.}
|
12
|
-
spec.description = %q{Output the tracklist of an album from a directory.}
|
13
|
-
spec.homepage = "https://gitlab.com/DomenicF/track_list"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
-
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://gitlab.com/DomenicF/track_list"
|
20
|
-
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
end
|
27
|
-
spec.bindir = "bin"
|
28
|
-
spec.executables = ["tracklist"]
|
29
|
-
spec.require_paths = ["lib"]
|
30
|
-
|
31
|
-
spec.
|
32
|
-
spec.add_development_dependency "bundler", "
|
33
|
-
spec.add_development_dependency "rake", "~>
|
34
|
-
end
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "track_list/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "track_list"
|
7
|
+
spec.version = TrackList::VERSION
|
8
|
+
spec.authors = ["Domenic Fiore"]
|
9
|
+
spec.email = ["domenicfiore@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Get the tracklist of a directory.}
|
12
|
+
spec.description = %q{Output the tracklist of an album from a directory.}
|
13
|
+
spec.homepage = "https://gitlab.com/DomenicF/track_list"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/DomenicF/track_list"
|
20
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "bin"
|
28
|
+
spec.executables = ["tracklist"]
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "taglib-ruby", "~> 1.1"
|
32
|
+
spec.add_development_dependency "bundler", ">= 2.2"
|
33
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: track_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domenic Fiore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: taglib-ruby
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
description: Output the tracklist of an album from a directory.
|
56
56
|
email:
|
57
57
|
- domenicfiore@gmail.com
|
@@ -72,6 +72,8 @@ files:
|
|
72
72
|
- bin/tracklist
|
73
73
|
- lib/track_list.rb
|
74
74
|
- lib/track_list/directory_parser.rb
|
75
|
+
- lib/track_list/environment.rb
|
76
|
+
- lib/track_list/template_parser.rb
|
75
77
|
- lib/track_list/time_converter.rb
|
76
78
|
- lib/track_list/track_parser.rb
|
77
79
|
- lib/track_list/version.rb
|
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
100
|
- !ruby/object:Gem::Version
|
99
101
|
version: '0'
|
100
102
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.2.3
|
102
104
|
signing_key:
|
103
105
|
specification_version: 4
|
104
106
|
summary: Get the tracklist of a directory.
|