spfy 0.1.8 → 0.1.9

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.
Files changed (4) hide show
  1. data/README.md +2 -2
  2. data/lib/spfy.rb +106 -100
  3. data/spfy.gemspec +1 -1
  4. metadata +1 -1
data/README.md CHANGED
@@ -4,9 +4,9 @@
4
4
  **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
5
 
6
6
  ##Prerequisites
7
- A working Ruby installation version 1.9 or greater is assumed 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/).
7
+ 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
8
 
9
- [TagLib](http://developer.kde.org/~wheeler/taglib.html) is also required for Spfy to function. 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:
9
+ [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:
10
10
 
11
11
  | System: | Command: |
12
12
  |---------------|------------------------------------|
@@ -26,7 +26,7 @@ require "taglib"
26
26
  require 'find'
27
27
  require 'uri'
28
28
 
29
- $version = "0.1.8"
29
+ $version = "0.1.9"
30
30
  $dirs = []
31
31
 
32
32
  # The main Spfy class
@@ -70,125 +70,131 @@ class Spfy
70
70
  end
71
71
 
72
72
  # start processing source paths
73
- begin
74
- if options.output.any?
75
- # source path(s) provided, output should be to disk
73
+ if options.output.any?
74
+ # source path(s) provided, output should be to disk
76
75
 
76
+ # open output file for writing
77
+ begin
77
78
  xmlFile = File.open(options.output[0], "w")
78
-
79
- print "Generating XML.."
79
+ rescue
80
+ puts "Unable to open output file for writing."
81
+ puts simple_usage
82
+ exit
83
+ end
84
+
85
+ print "Generating XML.."
86
+
87
+ # write XSPF header
88
+ xmlFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
89
+ xmlFile.write("<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n")
90
+ xmlFile.write("\t<trackList>\n")
91
+
92
+ # repeat for each source dir argument
93
+ $dirs.each do |dir|
80
94
 
81
- # write XSPF header
82
- xmlFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
83
- xmlFile.write("<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n")
84
- xmlFile.write("\t<trackList>\n")
85
-
86
- # repeat for each source dir argument
87
- $dirs.each do |dir|
88
-
95
+ begin
96
+
89
97
  # repeat for each file recursively
90
98
  Find.find(dir) do |path|
91
99
 
92
- begin
93
- TagLib::FileRef.open(path) do |fileref|
94
-
95
- tag = fileref.tag
96
-
97
- # skip files with no tags
98
- next if tag.nil?
99
-
100
- # write track metadata
101
- xmlFile.write("\t\t<track>\n")
102
-
103
- if !options.hide_location
104
- # generate a percent encoded string from the local path
105
- encoded_path = URI.escape(path)
106
- xmlFile.write("\t\t\t<location>file://#{encoded_path}</location>\n")
107
- end
108
-
109
- xmlFile.write("\t\t\t<title>#{tag.title}</title>\n") if !options.hide_title and !tag.title.nil?
110
- xmlFile.write("\t\t\t<creator>#{tag.artist}</creator>\n") if !options.hide_artist and !tag.artist.nil?
111
- xmlFile.write("\t\t\t<album>#{tag.album}</album>\n") if !options.hide_album and !tag.album.nil?
112
-
113
- if !options.hide_tracknum and !tag.track.nil?
114
- if tag.track > 0
115
- xmlFile.write("\t\t\t<trackNum>#{tag.track}</trackNum>\n")
116
- end
100
+ TagLib::FileRef.open(path) do |fileref|
101
+
102
+ tag = fileref.tag
103
+
104
+ # skip files with no tags
105
+ next if tag.nil?
106
+
107
+ # write track metadata
108
+ xmlFile.write("\t\t<track>\n")
109
+
110
+ if !options.hide_location
111
+ # generate a percent encoded string from the local path
112
+ encoded_path = URI.escape(path)
113
+ xmlFile.write("\t\t\t<location>file://#{encoded_path}</location>\n")
114
+ end
115
+
116
+ xmlFile.write("\t\t\t<title>#{tag.title}</title>\n") if !options.hide_title and !tag.title.nil?
117
+ xmlFile.write("\t\t\t<creator>#{tag.artist}</creator>\n") if !options.hide_artist and !tag.artist.nil?
118
+ xmlFile.write("\t\t\t<album>#{tag.album}</album>\n") if !options.hide_album and !tag.album.nil?
119
+
120
+ if !options.hide_tracknum and !tag.track.nil?
121
+ if tag.track > 0
122
+ xmlFile.write("\t\t\t<trackNum>#{tag.track}</trackNum>\n")
117
123
  end
118
-
119
- xmlFile.write("\t\t</track>\n")
120
124
  end
121
- rescue Exception => e
122
- next
125
+
126
+ xmlFile.write("\t\t</track>\n")
123
127
  end
124
128
  end
125
- end
126
-
127
- # write XSPF footer
128
- xmlFile.write("\t</trackList>\n")
129
- xmlFile.write("</playlist>\n")
130
-
131
- xmlFile.close
132
-
133
- print " success\n"
134
-
135
- else
136
- # no source path(s) provided, output to stdout
137
-
138
- # write XSPF header
139
- puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
140
- puts "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
141
- puts "\t<trackList>\n"
142
-
143
- # repeat for each source dir argument
144
- $dirs.each do |dir|
129
+ rescue SystemExit, Interrupt
130
+ abort("\nCancelled, exiting..")
131
+ rescue Exception => e
132
+ next
133
+ end # begin
134
+ end # $dirs.each do |dir|
135
+
136
+ # write XSPF footer
137
+ xmlFile.write("\t</trackList>\n")
138
+ xmlFile.write("</playlist>\n")
139
+
140
+ xmlFile.close
141
+
142
+ print " success\n"
143
+
144
+ else
145
+ # no source path(s) provided, output to stdout
146
+
147
+ # write XSPF header
148
+ puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
149
+ puts "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
150
+ puts "\t<trackList>\n"
151
+
152
+ # repeat for each source dir argument
153
+ $dirs.each do |dir|
154
+
155
+ begin
145
156
 
146
157
  # repeat for each file recursively
147
158
  Find.find(dir) do |path|
148
159
 
149
- begin
150
- TagLib::FileRef.open(path) do |fileref|
160
+ TagLib::FileRef.open(path) do |fileref|
161
+
162
+ tag = fileref.tag
163
+
164
+ # skip files with no tags
165
+ next if tag.nil?
151
166
 
152
- tag = fileref.tag
153
-
154
- # skip files with no tags
155
- next if tag.nil?
156
-
157
- # output track metadata
158
- puts "\t\t<track>\n"
159
-
160
- if !options.hide_location
161
- encoded_path = URI.escape(path)
162
- puts "\t\t\t<location>file://#{encoded_path}</location>\n"
163
- end
164
-
165
- puts "\t\t\t<title>#{tag.title}</title>\n" if !options.hide_title and !tag.title.nil?
166
- puts "\t\t\t<creator>#{tag.artist}</creator>\n" if !options.hide_artist and !tag.artist.nil?
167
- puts "\t\t\t<album>#{tag.album}</album>\n" if !options.hide_album and !tag.album.nil?
168
-
169
- if !options.hide_tracknum and !tag.track.nil?
170
- if tag.track > 0
171
- puts "\t\t\t<trackNum>#{tag.track}</trackNum>\n"
172
- end
167
+ # output track metadata
168
+ puts "\t\t<track>\n"
169
+
170
+ if !options.hide_location
171
+ encoded_path = URI.escape(path)
172
+ puts "\t\t\t<location>file://#{encoded_path}</location>\n"
173
+ end
174
+
175
+ puts "\t\t\t<title>#{tag.title}</title>\n" if !options.hide_title and !tag.title.nil?
176
+ puts "\t\t\t<creator>#{tag.artist}</creator>\n" if !options.hide_artist and !tag.artist.nil?
177
+ puts "\t\t\t<album>#{tag.album}</album>\n" if !options.hide_album and !tag.album.nil?
178
+
179
+ if !options.hide_tracknum and !tag.track.nil?
180
+ if tag.track > 0
181
+ puts "\t\t\t<trackNum>#{tag.track}</trackNum>\n"
173
182
  end
174
-
175
- puts "\t\t</track>\n"
176
183
  end
177
- rescue Exception => e
178
- next
184
+
185
+ puts "\t\t</track>\n"
179
186
  end
180
187
  end
181
- end
182
-
183
- # write XSPF footer
184
- puts "\t</trackList>\n"
185
- puts "</playlist>\n"
186
- end
188
+ rescue SystemExit, Interrupt
189
+ abort("\nCancelled, exiting..")
190
+ rescue Exception => e
191
+ next
192
+ end # begin
193
+ end # $dirs.each do |dir|
187
194
 
188
- rescue SystemExit, Interrupt
189
- abort("Cancelled, exiting..")
190
- rescue Exception => e
191
- abort("Exiting.. (#{e})")
195
+ # write XSPF footer
196
+ puts "\t</trackList>\n"
197
+ puts "</playlist>\n"
192
198
  end
193
199
 
194
200
  end # def self.generate
@@ -21,7 +21,7 @@
21
21
 
22
22
  Gem::Specification.new do |s|
23
23
  s.name = 'spfy'
24
- s.version = '0.1.8'
24
+ s.version = '0.1.9'
25
25
  s.date = '2012-05-06'
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.'
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.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: