spfy 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -8
  3. data/lib/spfy.rb +58 -43
  4. data/spfy.gemspec +1 -1
  5. data/test.sh +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf17141af7094be0bea0539178739b64a2026191
4
- data.tar.gz: 3b4de8e6335d3c118ac4a3198faa16190c7820bc
3
+ metadata.gz: bf086944e45afbf5e0b3518d00b3ebaaaa261f9b
4
+ data.tar.gz: f32cc7491b140891272a0c56bc25968b1a7a69ad
5
5
  SHA512:
6
- metadata.gz: 10913f7fd7750d4983345aeb4957395b5529f4a41b2984b06906cb239fdd70662858e67ee0d806e2215e7dea6e3269483e2e95717c0940279612586c19727427
7
- data.tar.gz: ab139fee487a2c809465c9b8d4c244ebb0e71bbf7ecf88ef848943027e33cc7fffbda5748d4f8f9b886b8a218108c771f33d7ecb2004adf09702347055c56609
6
+ metadata.gz: d2357fef3dae3191e26b38a30e0a6852b19bfb675271aa52958d59d336a834cdafefad75653811bda4fa7b8b1d05580878e1063f6a9d24267365dd89c4ea66b2
7
+ data.tar.gz: 65d1bf4328dacaf7ca232a5b9db632daccc1d9f294f01afba9fccaf1a8c6180b565f5798f6571f901a0d4827539f6b54c0cf85e0596a85a6141680c4e801fcac
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # Spfy ("spiffy")
1
+ ## Spfy ("spiffy")
2
+ [![Code Climate](https://codeclimate.com/github/marcransome/Spfy.png)](https://codeclimate.com/github/marcransome/Spfy)
2
3
 
3
- ## Overview
4
+ ### Overview
4
5
  **Spfy** is a command-line tool for generating [XSPF](http://xspf.org/) playlists from metadata stored in several popular audio formats and is developed entirely in [Ruby](http://www.ruby-lang.org/). It takes one or more local directory paths as input, extracts metadata tags from any audio files that it encounters, and generates a valid XSPF playlist.
5
6
 
6
- ## Prerequisites
7
+ ### Prerequisites
7
8
  A working Ruby installation (version 1.9 or greater) is required for Spfy to work, but this is outside the scope of this guide. For more information refer to the [official installation procedure](http://www.ruby-lang.org/en/downloads/).
8
9
 
9
10
  [TagLib](http://developer.kde.org/~wheeler/taglib.html) is also required. Follow the steps below (taken from the [taglib-ruby installation guide](http://robinst.github.com/taglib-ruby/)) to install the necessary files for your respective system type:
@@ -15,12 +16,12 @@ A working Ruby installation (version 1.9 or greater) is required for Spfy to wor
15
16
  | Brew | `brew install taglib` |
16
17
  | MacPorts | `sudo port install taglib` |
17
18
 
18
- ## Installation
19
+ ### Installation
19
20
  With the prerequisites above taken care of Spfy can be installed with the following command:
20
21
 
21
22
  $ gem install spfy
22
23
 
23
- ## Using Spfy
24
+ ### Using Spfy
24
25
  By default, Spfy will output a formatted XSPF playlist to the standard output stream that will include _location_, _title_, _creator_, _album_, and _trackNum_ elements for each audio file where available.
25
26
 
26
27
  The general syntax for Spfy is `spfy [options] dir1 ... dirN`, where _dir1 ... dirN_ is one or more paths to directories containing audio files.
@@ -58,13 +59,13 @@ Command-line arguments allow you to control which elements Spfy outputs:
58
59
 
59
60
  For additional options use `spfy --help`.
60
61
 
61
- ## License
62
+ ### License
62
63
  Spfy is free software, and you are welcome to redistribute it under certain conditions. See the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for more details.
63
64
 
64
- ## Acknowledgments
65
+ ### Acknowledgments
65
66
  Spfy uses the following third party software components:
66
67
 
67
68
  * [taglib-ruby](http://robinst.github.com/taglib-ruby/) by Robin Stocker
68
69
 
69
- ## Comments or suggestions?
70
+ ### Comments or suggestions?
70
71
  Email me at [marc.ransome@fidgetbox.co.uk](mailto://marc.ransome@fidgetbox.co.uk) with bug reports, feature requests or general comments and follow [@marcransome](http://www.twitter.com/marcransome) for updates.
@@ -18,6 +18,7 @@
18
18
  #
19
19
  # You should have received a copy of the GNU General Public License
20
20
  # along with Spfy. If not, see <http://www.gnu.org/licenses/>.
21
+ #
21
22
 
22
23
  require "spfy/optionreader"
23
24
  require "optparse"
@@ -28,18 +29,18 @@ require "uri"
28
29
 
29
30
  class Spfy
30
31
 
31
- VERSION = "0.3.1"
32
+ VERSION = "1.0.0"
32
33
  USAGE = "Use `#{File.basename($0)} --help` for available options."
33
34
 
34
- @xspf_tags = {
35
+ @xml_tags = {
35
36
  :header => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
36
37
  "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"\
37
38
  "\t<trackList>\n",
38
39
  :footer => "\t</trackList>\n</playlist>\n",
39
40
  :title_start => "\t\t\t<title>",
40
41
  :title_end => "</title>\n",
41
- :creator_start => "\t\t\t<creator>",
42
- :creator_end => "</creator>\n",
42
+ :artist_start => "\t\t\t<creator>",
43
+ :artist_end => "</creator>\n",
43
44
  :album_start => "\t\t\t<album>",
44
45
  :album_end => "</album>\n",
45
46
  :location_start => "\t\t\t<location>file://",
@@ -52,9 +53,8 @@ class Spfy
52
53
 
53
54
  def self.parse_args
54
55
  begin
55
- # test for zero arguments
56
56
  if ARGV.empty? then
57
- self.exit_with_banner
57
+ exit_with_banner
58
58
  end
59
59
 
60
60
  # parse command-line arguments
@@ -64,62 +64,77 @@ class Spfy
64
64
  if @options.dirs.empty?
65
65
  exit_with_message("No source path(s) specified.")
66
66
  end
67
-
67
+
68
68
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error
69
69
  exit_with_message(error.to_s.capitalize)
70
70
  end
71
71
  end
72
72
 
73
73
  def self.generate_xml
74
+ @tracks_processed = 0
74
75
 
75
76
  if @options.output.any?
76
77
  puts "Generating XML..."
77
- self.capture_stdout
78
+ capture_stdout
78
79
  end
79
80
 
80
- puts @xspf_tags[:header]
81
- tracks_processed = 0
82
-
81
+ puts @xml_tags[:header]
83
82
  @options.dirs.each do |dir|
84
- begin
85
- Find.find(dir) do |path|
86
- TagLib::FileRef.open(path) do |fileref|
87
- tag = fileref.tag
88
-
89
- next if tag.nil? # skip files with no tags
90
-
91
- puts "#{@xspf_tags[:track_start]}"
92
-
93
- if !@options.hide_location
94
- encoded_path = URI.escape(path).sub("%5C", "/") # percent encode string for local path
95
- puts "#{@xspf_tags[:location_start]}#{encoded_path}#{@xspf_tags[:location_end]}"
96
- end
97
-
98
- puts "#{@xspf_tags[:title_start]}#{tag.title}#{@xspf_tags[:title_end]}" if !@options.hide_title and !tag.title.nil?
99
- puts "#{@xspf_tags[:creator_start]}#{tag.artist}#{@xspf_tags[:creator_end]}" if !@options.hide_artist and !tag.artist.nil?
100
- puts "#{@xspf_tags[:album_start]}#{tag.album}#{@xspf_tags[:album_end]}" if !@options.hide_album and !tag.album.nil?
101
-
102
- if !@options.hide_tracknum and !tag.track.nil?
103
- if tag.track > 0
104
- puts "#{@xspf_tags[:track_num_start]}#{tag.track}#{@xspf_tags[:track_num_end]}"
105
- end
106
- end
107
-
108
- puts "#{@xspf_tags[:track_end]}"
109
-
110
- tracks_processed += 1
111
- break if @options.tracks_to_process[0].to_i > 0 and tracks_processed == options.tracks_to_process[0].to_i
83
+ catch :MaxTracksReached do
84
+ begin
85
+ Find.find(dir) do |path|
86
+ xml_for_path(path)
112
87
  end
88
+ rescue Interrupt
89
+ abort("\nCancelled, exiting..")
113
90
  end
114
- rescue Interrupt
115
- abort("\nCancelled, exiting..")
116
91
  end
117
92
  end
118
- puts @xspf_tags[:footer]
93
+ puts @xml_tags[:footer]
119
94
 
120
95
  $stdout = STDOUT if @options.output.any?
121
96
  end
122
97
 
98
+ def self.xml_for_path(path)
99
+ TagLib::FileRef.open(path) do |fileref|
100
+ tags = fileref.tag
101
+
102
+ next if tags.nil? # skip files with no tags
103
+
104
+ puts "#{@xml_tags[:track_start]}"
105
+ parse_location(path)
106
+ parse_tag(tags.title, @options.hide_title, @xml_tags[:title_start], @xml_tags[:title_end])
107
+ parse_tag(tags.artist, @options.hide_artist, @xml_tags[:artist_start], @xml_tags[:artist_end])
108
+ parse_tag(tags.album, @options.hide_album, @xml_tags[:album_start], @xml_tags[:album_end])
109
+ parse_track_num(tags.track)
110
+ puts "#{@xml_tags[:track_end]}"
111
+
112
+ @tracks_processed += 1
113
+ throw :MaxTracksReached if @options.tracks_to_process[0].to_i > 0 and @tracks_processed == @options.tracks_to_process[0].to_i
114
+ end
115
+ end
116
+
117
+ def self.parse_location(path)
118
+ if !@options.hide_location
119
+ encoded_path = URI.escape(path).sub("%5C", "/") # percent encode string for local path
120
+ puts "#{@xml_tags[:location_start]}#{encoded_path}#{@xml_tags[:location_end]}"
121
+ end
122
+ end
123
+
124
+ def self.parse_tag(tag, suppress_output, start_xml, end_xml)
125
+ if !tag.nil? and !suppress_output
126
+ puts "#{start_xml}#{tag}#{end_xml}"
127
+ end
128
+ end
129
+
130
+ def self.parse_track_num(track_num)
131
+ if !@options.hide_tracknum and !track_num.nil?
132
+ if track_num > 0
133
+ puts "#{@xml_tags[:track_num_start]}#{track_num}#{@xml_tags[:track_num_end]}"
134
+ end
135
+ end
136
+ end
137
+
123
138
  def self.exit_with_message(message)
124
139
  puts message if message
125
140
  exit_with_banner
@@ -133,5 +148,5 @@ class Spfy
133
148
  def self.capture_stdout
134
149
  $stdout = File.open(@options.output[0], "w")
135
150
  end
136
-
151
+ private_class_method :xml_for_path, :parse_location, :parse_tag, :parse_track_num, :exit_with_message, :exit_with_banner, :capture_stdout
137
152
  end
@@ -21,7 +21,7 @@
21
21
 
22
22
  Gem::Specification.new do |s|
23
23
  s.name = 'spfy'
24
- s.version = '0.3.1'
24
+ s.version = '1.0.0'
25
25
  s.date = '2013-07-28'
26
26
  s.summary = 'XSPF playlist generator'
27
27
  s.description = 'Spfy is a simple command-line tool for generating XSPF playlists from metadata stored in several popular audio formats.'
data/test.sh CHANGED
@@ -20,7 +20,7 @@
20
20
  # You should have received a copy of the GNU General Public License
21
21
  # along with Spfy. If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
- version_from_gemspec=$( grep 's.version' spfy.gemspec | cut -c 16-20 )
23
+ version_from_gemspec=$( grep 's.version' spfy.gemspec | cut -c 20-24 )
24
24
  gem_file="spfy-$version_from_gemspec.gem"
25
25
 
26
26
  echo "Removing outdated gem files.."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Ransome