spfy 0.1 → 0.1.1

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.
@@ -8,10 +8,9 @@ class OptionReader
8
8
  options.hide_title = false
9
9
  options.hide_artist = false
10
10
  options.hide_album = false
11
- options.hide_tracknum = false
12
11
 
13
12
  opts = OptionParser.new do |opts|
14
- opts.banner = "Usage: #{File.basename($0)} [options] [source]"
13
+ opts.banner = "Usage: #{File.basename($0)} [options] [dir1 ... dirx]"
15
14
 
16
15
  opts.separator ""
17
16
  opts.separator "Output:"
@@ -32,10 +31,6 @@ class OptionReader
32
31
  options.hide_album = true
33
32
  end
34
33
 
35
- opts.on("-n", "--no-tracknum", "Suppress track number in output") do
36
- options.hide_tracknum = true
37
- end
38
-
39
34
  opts.separator ""
40
35
  opts.separator "Common options:"
41
36
 
data/lib/spfy.rb CHANGED
@@ -24,15 +24,18 @@ require "optparse"
24
24
  require "ostruct"
25
25
  require "taglib"
26
26
 
27
- $version = "0.1"
27
+ $version = "0.1.1"
28
28
  $dirs = []
29
29
 
30
+ # The main Spfy class
30
31
  class Spfy
31
32
 
33
+ ##
34
+ # Starts the XSPF generator.
35
+ #
32
36
  def self.generate
33
- #
34
- # Read command-line arguments
35
- #
37
+
38
+ # start processing command line arguments
36
39
  begin
37
40
 
38
41
  # short usage banner
@@ -64,85 +67,90 @@ class Spfy
64
67
  exit
65
68
  end
66
69
 
67
- #
68
- # Process valid paths
69
- #
70
+ # start processing source paths
70
71
  begin
71
72
  if options.output.any?
72
-
73
- # test whether there is an option for data to output
74
- if options.hide_title and options.hide_artist and options.hide_album
75
-
76
- # all data has been suppressed, report to user
77
- puts "All tags suppressed, no XML file created."
78
- exit
79
- end
80
73
 
81
74
  xmlFile = File.open(options.output[0], "w")
82
75
 
83
76
  print "Generating XML.."
84
-
77
+
78
+ # write XSPF header
85
79
  xmlFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
86
- xmlFile.write("<playlist version=\"1\" xmlns=\"http:#xspf.org/ns/0/\">\n")
80
+ xmlFile.write("<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n")
87
81
  xmlFile.write("\t<trackList>\n")
88
82
 
89
- Dir.foreach($dirs[0]).sort.each do |file|
90
- next if file == '.' or file == '..' or
91
- next if file.start_with? '.'
83
+ # repeat for each source path specified
84
+ $dirs.each do |path|
92
85
 
93
- begin
94
- TagLib::FileRef.open($dirs[0] + "/" + file) do |fileref|
95
-
96
- tag = fileref.tag
97
-
98
- # skip files with no tags
99
- next if tag.title.empty? and tag.artist.empty? and tag.album.empty?
100
-
101
- xmlFile.write("\t\t<track>\n")
102
- #xmlFile.write("\t\t\t<location>http:##{host}#{musicDir}/#{file}</location>\n")
103
- xmlFile.write("\t\t\t<title>#{tag.title}</title>\n") if !options.hide_title and !tag.title.empty?
104
- xmlFile.write("\t\t\t<creator>#{tag.artist}</creator>\n") if !options.hide_artist and !tag.artist.empty?
105
- xmlFile.write("\t\t\t<album>#{tag.album}</album>\n") if !options.hide_album and !tag.album.empty?
106
- xmlFile.write("\t\t</track>\n")
107
-
86
+ # repeat for each file
87
+ Dir.foreach(path).sort.each do |file|
88
+ next if file == '.' or file == '..' or
89
+ next if file.start_with? '.'
90
+
91
+ begin
92
+ TagLib::FileRef.open(path + "/" + file) do |fileref|
93
+
94
+ tag = fileref.tag
95
+
96
+ # skip files with no tags
97
+ next if tag.title.empty? and tag.artist.empty? and tag.album.empty? and tag.track.empty?
98
+
99
+ # write track metadata
100
+ xmlFile.write("\t\t<track>\n")
101
+ #xmlFile.write("\t\t<location>file:/#{path}#{file}</location>\n")
102
+ xmlFile.write("\t\t\t<title>#{tag.title}</title>\n") if !options.hide_title and !tag.title.empty?
103
+ xmlFile.write("\t\t\t<creator>#{tag.artist}</creator>\n") if !options.hide_artist and !tag.artist.empty?
104
+ xmlFile.write("\t\t\t<album>#{tag.album}</album>\n") if !options.hide_album and !tag.album.empty?
105
+ xmlFile.write("\t\t</track>\n")
106
+ end
107
+ rescue Exception => e
108
+ next
108
109
  end
109
- rescue Exception => e
110
- next
111
110
  end
112
111
  end
113
112
 
113
+ # write XSPF footer
114
114
  xmlFile.write("\t</trackList>\n")
115
115
  xmlFile.write("</playlist>\n")
116
+
116
117
  xmlFile.close
117
118
 
118
119
  print " success\n"
120
+
119
121
  else
120
122
  puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
121
- puts "<playlist version=\"1\" xmlns=\"http:#xspf.org/ns/0/\">\n"
123
+ puts "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
122
124
  puts "\t<trackList>\n"
123
125
 
124
- Dir.foreach($dirs[0]).sort.each do |file|
125
- next if file == '.' or file == '..' or
126
- next if file.start_with? '.'
127
-
128
- begin
129
- TagLib::FileRef.open($dirs[0] + "/" + file) do |fileref|
126
+ # repeat for each source path
127
+ $dirs.each do |path|
128
+
129
+ # repeat for each file
130
+ Dir.foreach(path).sort.each do |file|
131
+ next if file == '.' or file == '..' or
132
+ next if file.start_with? '.'
130
133
 
131
- tag = fileref.tag
132
-
133
- # skip files with no tags
134
- next if tag.title.empty? and tag.artist.empty? and tag.album.empty?
135
-
136
- puts "\t\t<track>\n"
137
- #xmlFile.write("\t\t\t<location>http:##{host}#{musicDir}/#{file}</location>\n")
138
- puts "\t\t\t<title>#{tag.title}</title>\n"
139
- puts "\t\t\t<creator>#{tag.artist}</creator>\n"
140
- puts "\t\t\t<album>#{tag.album}</album>\n"
141
- puts "\t\t</track>\n"
134
+ begin
135
+ # FIX THIS AS IT MAY NOT WORK MULTIPLATFORM!!!
136
+ TagLib::FileRef.open(path + "/" + file) do |fileref|
142
137
 
138
+ tag = fileref.tag
139
+
140
+ # skip files with no tags
141
+ next if tag.title.empty? and tag.artist.empty? and tag.album.empty? and tag.track.empty?
142
+
143
+ # write track metadata
144
+ puts "\t\t<track>\n"
145
+ #puts "\t\t\t<location>file:/#{path}#{file}</location>"
146
+ puts "\t\t\t<title>#{tag.title}</title>\n" if !options.hide_title and !tag.title.empty?
147
+ puts "\t\t\t<creator>#{tag.artist}</creator>\n" if !options.hide_artist and !tag.artist.empty?
148
+ puts "\t\t\t<album>#{tag.album}</album>\n" if !options.hide_album and !tag.album.empty?
149
+ puts "\t\t</track>\n"
150
+ end
151
+ rescue Exception => e
152
+ next
143
153
  end
144
- rescue Exception => e
145
- next
146
154
  end
147
155
  end
148
156
 
@@ -156,6 +164,7 @@ class Spfy
156
164
  abort("Exiting.. (#{e})")
157
165
  end
158
166
 
159
- end
160
- end
167
+ end # def self.generate
168
+
169
+ end # class Spyf
161
170
 
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.1'
25
25
  s.date = '2012-05-05'
26
26
  s.summary = 'XSPF playlist generator.'
27
27
  s.description = 'Spfy is a simple command-line ruby tool for generating XSPF playlists from metadata stored in several popular audio formats.'
@@ -30,5 +30,5 @@ Gem::Specification.new do |s|
30
30
  s.files = `git ls-files`.split("\n")
31
31
  s.executables << 'spfy'
32
32
  s.add_runtime_dependency 'taglib-ruby', '>= 0.5.0'
33
- s.homepage = 'http://rubygems.org/gems/spfy'
33
+ s.homepage = 'http://github.com/marcransome/spfy'
34
34
  end
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'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,7 +41,7 @@ files:
41
41
  - lib/spfy/optionreader.rb
42
42
  - license.txt
43
43
  - spfy.gemspec
44
- homepage: http://rubygems.org/gems/spfy
44
+ homepage: http://github.com/marcransome/spfy
45
45
  licenses: []
46
46
  post_install_message:
47
47
  rdoc_options: []
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 1.8.24
64
+ rubygems_version: 1.8.23
65
65
  signing_key:
66
66
  specification_version: 3
67
67
  summary: XSPF playlist generator.