track_list 0.2.0 → 0.3.0

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: 479a619595efec9dc0388637532e62eb2d85f49d1286c5632d14c44d9d45e373
4
- data.tar.gz: ce39a80fae12241bce71c8527c9cd83ca0c237473e2fabcd7c22ed2a3a63df3d
3
+ metadata.gz: 68768df5d84a827b02666436938a4f8f1a55f1bce90ede8a0f9fd339b0ea159b
4
+ data.tar.gz: ea4ed055dd77e1412e06b68ed660456fdc2ca20e6eeccbe34db9b5d8c84d3ea5
5
5
  SHA512:
6
- metadata.gz: 8d64d0707d4b68b5471574b88e7b5b4c14fdf1fa49c79c64c1246ba99cd56e848e59e5e305fc02c5ad4aea2c07f5d1f39e00c26e534ba375eb6c7f4f445f8370
7
- data.tar.gz: 9f626e37d349ca83a565eeb0a2d60a52dab46be1fd8419b2f4c7369290be48d228807eec3f1fa668299a5082446d5cb5f30f49cae0d7673a032c07688232156f
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,23 +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.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.
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
@@ -1,5 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in track_list.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in track_list.gemspec
4
+ gemspec
5
+ gem 'rubocop', group: 'development'
5
6
  gem "taglib-ruby"
data/Gemfile.lock CHANGED
@@ -1,23 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- track_list (0.2.0)
5
- taglib-ruby (~> 0.7)
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
- rake (10.5.0)
11
- taglib-ruby (0.7.1)
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
- ruby
36
+ x86_64-linux
15
37
 
16
38
  DEPENDENCIES
17
- bundler (~> 2.0)
18
- rake (~> 10.0)
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.0.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,77 +1,82 @@
1
- # TrackList
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 tracklist 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 tracklists 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 tracklist. On first run of the program, the program will create a .track_list.yaml file in your home directory. The default output is as follows:
51
-
52
- `output: "%TRACK%. %TITLE% (%LENGTH%)"`
53
-
54
- You can change this string with the following tags to format it the way you want it:
55
- - `%TRACK%` - The track number of a given audio file.
56
- - `%TITLE%` - The title tag of a given audio file.
57
- - `%LENGTH%` - The length of a given audio file in `[hours:minutes:seconds]`
58
- - `%ARTIST%` - The artist tag of a given audio file.
59
- - `%ALBUM%` - The album tag of a given audio file.
60
- - `%YEAR%` - The year tag of a given audio file.
61
- - `%GENRE%` - The genre tag of a given audio file.
62
- - `%COMMENT%` - The comment tag of a given audio file.
63
-
64
- 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.
65
-
66
- ## Usage
67
-
68
- `tracklist <album directory>`
69
-
70
-
71
- ## Contributing
72
-
73
- Bug reports and pull requests are welcome on GitLab at https://gitlab.com/DomenicF/track_list/issues.
74
-
75
- ## License
76
-
77
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,41 +1,42 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "track_list"
4
- require 'getoptlong'
5
- require 'track_list/template_parser'
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
- template_parser = TrackList::TemplateParser.new('~/.track_list.yaml')
32
-
33
- # Let's create a default config file if one does not exist.
34
- unless template_parser.config_exists?
35
- template_parser.create_default_config
36
- end
37
-
38
- # Loop over each track and output to terminal.
39
- dir.parse.each do |track|
40
- puts track.parse if track.parse.is_a? String
41
- end
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,51 +1,51 @@
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
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
@@ -1,41 +1,45 @@
1
- require 'yaml'
2
-
3
- module TrackList
4
-
5
- # A helper class to read/write a config file.
6
-
7
- class TemplateParser
8
-
9
- # Pass in a file path to read/write the config file.
10
-
11
- def initialize(config_path)
12
- @config_path = config_path
13
- end
14
-
15
- # Return the config file in a Ruby-readable format.
16
-
17
- def load
18
- return YAML.load(File.open(File.expand_path(@config_path)))
19
- end
20
-
21
- # Check if the config file already exists.
22
-
23
- def config_exists?
24
- if (File.exist?(File.expand_path(@config_path)))
25
- return true
26
- else
27
- return false
28
- end
29
- end
30
-
31
- # Create a default config file with some basic settings.
32
-
33
- def create_default_config
34
- config = { "output" => "%TRACK%. %TITLE% (%LENGTH%)" }
35
- out_file = File.new(File.expand_path(@config_path), 'w')
36
- out_file.puts(config.to_yaml)
37
- out_file.close
38
- end
39
-
40
- end
41
- end
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,30 +1,30 @@
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
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
30
30
  end
@@ -1,64 +1,66 @@
1
- require 'taglib'
2
- require 'track_list/time_converter'
3
- require 'track_list/template_parser'
4
-
5
- module TrackList
6
- ##
7
- # The purpose of this class is to parse a single track and return a formatted
8
- # string.
9
-
10
- class TrackParser
11
-
12
- ##
13
- # When initializing the class, you must pass in a file path to the +track+
14
- # you want parsed.
15
- #
16
- # @param [String] track The track to be parsed.
17
-
18
- def initialize(track)
19
- @track = track
20
- end
21
-
22
- ##
23
- # The bulk of the work is done in this method. Calling this method returns
24
- # a parsed track in a formatted string.
25
- #
26
- # @return [String] if valid audio file.
27
-
28
- def parse
29
- TagLib::FileRef.open(@track) do |fileref|
30
- unless fileref.null?
31
- tag = fileref.tag
32
- properties = fileref.audio_properties
33
- time_conversion = TrackList::TimeConverter.new(properties.length)
34
- length = time_conversion.format_time
35
-
36
- template_parser = TrackList::TemplateParser.new('~/.track_list.yaml')
37
- template = template_parser.load
38
-
39
- template_strings = {
40
- '%TRACK%' => tag.track.to_s,
41
- '%TITLE%' => tag.title,
42
- '%LENGTH%' => length,
43
- '%ARTIST%' => tag.artist,
44
- '%ALBUM%' => tag.album,
45
- '%YEAR%' => tag.year.to_s,
46
- '%GENRE%' => tag.genre,
47
- '%COMMENT%' => tag.comment
48
- }
49
-
50
- parsed_string = ''
51
-
52
- template_strings.each do |key, val|
53
- if template['output'].include? key
54
- parsed_string = template['output'].gsub!(key, val)
55
- end
56
- end
57
-
58
- return parsed_string
59
- end
60
- end
61
- end
62
-
63
- end
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
64
66
  end
@@ -1,3 +1,3 @@
1
- module TrackList
2
- VERSION = "0.2.0"
3
- end
1
+ module TrackList
2
+ VERSION = "0.3.0"
3
+ end
data/lib/track_list.rb CHANGED
@@ -1,12 +1,12 @@
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
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.add_dependency "taglib-ruby", "~> 0.7"
32
- spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
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.2.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: 2019-08-09 00:00:00.000000000 Z
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: '0.7'
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: '0.7'
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.0'
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.0'
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: '10.0'
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: '10.0'
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,7 @@ 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
75
76
  - lib/track_list/template_parser.rb
76
77
  - lib/track_list/time_converter.rb
77
78
  - lib/track_list/track_parser.rb
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
100
  - !ruby/object:Gem::Version
100
101
  version: '0'
101
102
  requirements: []
102
- rubygems_version: 3.0.4
103
+ rubygems_version: 3.2.3
103
104
  signing_key:
104
105
  specification_version: 4
105
106
  summary: Get the tracklist of a directory.