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.
- data/README.md +2 -2
- data/lib/spfy.rb +106 -100
- data/spfy.gemspec +1 -1
- 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
|
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
|
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
|
|---------------|------------------------------------|
|
data/lib/spfy.rb
CHANGED
@@ -26,7 +26,7 @@ require "taglib"
|
|
26
26
|
require 'find'
|
27
27
|
require 'uri'
|
28
28
|
|
29
|
-
$version = "0.1.
|
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
|
-
|
74
|
-
|
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
|
-
|
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
|
-
|
82
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if
|
114
|
-
|
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
|
-
|
122
|
-
|
125
|
+
|
126
|
+
xmlFile.write("\t\t</track>\n")
|
123
127
|
end
|
124
128
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
150
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
178
|
-
|
184
|
+
|
185
|
+
puts "\t\t</track>\n"
|
179
186
|
end
|
180
187
|
end
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
189
|
-
|
190
|
-
|
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
|
data/spfy.gemspec
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
|
22
22
|
Gem::Specification.new do |s|
|
23
23
|
s.name = 'spfy'
|
24
|
-
s.version = '0.1.
|
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.'
|