rack-musicindex 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/rack/musicindex.rb
CHANGED
@@ -21,7 +21,7 @@ module Rack
|
|
21
21
|
|
22
22
|
if dirs[path_info]
|
23
23
|
serve_podcast(env)
|
24
|
-
elsif static_paths.include?(path_info)
|
24
|
+
elsif static_paths.include?(URI.unescape(path_info))
|
25
25
|
serve_mp3(env)
|
26
26
|
else
|
27
27
|
status, headers, response = @app.call(env)
|
@@ -33,22 +33,26 @@ module Rack
|
|
33
33
|
def serve_podcast(env)
|
34
34
|
status, headers, response = @app.call(env)
|
35
35
|
|
36
|
+
method = env['REQUEST_METHOD']
|
36
37
|
body = podcast(env)
|
38
|
+
|
37
39
|
headers['Content-Type'] = 'application/xml;charset=utf-8'
|
38
40
|
headers["Content-Length"] = body.bytesize.to_s
|
39
41
|
|
40
|
-
[200, headers, [body]]
|
42
|
+
[200, headers, method == 'GET' ? [body] : []]
|
41
43
|
end
|
42
44
|
|
43
45
|
def serve_mp3(env)
|
44
46
|
status, headers, response = @app.call(env)
|
45
|
-
path_info = env['PATH_INFO']
|
46
47
|
|
48
|
+
method = env['REQUEST_METHOD']
|
49
|
+
path_info = URI.unescape(env['PATH_INFO'])
|
47
50
|
body = open(static_paths[path_info], 'rb').read
|
51
|
+
|
48
52
|
headers["Content-Type"] = 'audio/mpeg'
|
49
53
|
headers["Content-Length"] = body.bytesize.to_s
|
50
54
|
|
51
|
-
[200, headers, [body]]
|
55
|
+
[200, headers, method == 'GET' ? [body] : []]
|
52
56
|
end
|
53
57
|
|
54
58
|
def dirs
|
@@ -103,7 +107,7 @@ module Rack
|
|
103
107
|
req = Rack::Request.new(env)
|
104
108
|
url = req.url
|
105
109
|
files = files(path)
|
106
|
-
xml = ::Builder::XmlMarkup.new
|
110
|
+
xml = ::Builder::XmlMarkup.new(:indent => 2)
|
107
111
|
|
108
112
|
xml.instruct! :xml, :version => '1.0'
|
109
113
|
xml.rss :version => "2.0", 'xmlns:itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd' do
|
@@ -116,7 +120,7 @@ module Rack
|
|
116
120
|
tag = id3(file)
|
117
121
|
author = tag[:artist]
|
118
122
|
name = ::File.basename(file)
|
119
|
-
item_link = url + '/' + name
|
123
|
+
item_link = URI.escape(url + '/' + name)
|
120
124
|
|
121
125
|
xml.item do
|
122
126
|
xml.title tag[:name] || name
|
@@ -128,7 +132,6 @@ module Rack
|
|
128
132
|
if author
|
129
133
|
xml.author author
|
130
134
|
xml.itunes :author, author
|
131
|
-
xml.itunes :summary, author
|
132
135
|
end
|
133
136
|
end
|
134
137
|
end
|
File without changes
|
@@ -37,9 +37,9 @@ describe Rack::MusicIndex do
|
|
37
37
|
|
38
38
|
items.size.should eql(1)
|
39
39
|
item.xpath('title')[0].content.should eql('bar')
|
40
|
-
item.xpath('link')[0].content.should eql('http://example.org/foo/test.mp3')
|
41
|
-
item.xpath('guid')[0].content.should eql('http://example.org/foo/test.mp3')
|
42
|
-
item.xpath('enclosure')[0]['url'].should eql('http://example.org/foo/test.mp3')
|
40
|
+
item.xpath('link')[0].content.should eql('http://example.org/foo/test%20foo.mp3')
|
41
|
+
item.xpath('guid')[0].content.should eql('http://example.org/foo/test%20foo.mp3')
|
42
|
+
item.xpath('enclosure')[0]['url'].should eql('http://example.org/foo/test%20foo.mp3')
|
43
43
|
item.xpath('author')[0].content.should eql('foo')
|
44
44
|
item.xpath('itunes:author')[0].content.should eql('foo')
|
45
45
|
end
|
@@ -68,10 +68,10 @@ describe Rack::MusicIndex do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should return mp3' do
|
71
|
-
get '/foo/test.mp3'
|
71
|
+
get '/foo/test%20foo.mp3'
|
72
72
|
|
73
73
|
last_response.should be_ok
|
74
74
|
last_response['Content-Type'].should eql('audio/mpeg')
|
75
|
-
last_response.body.should eql(open(fixture('/foo/test.mp3'), 'rb').read)
|
75
|
+
last_response.body.should eql(open(fixture('/foo/test foo.mp3'), 'rb').read)
|
76
76
|
end
|
77
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-musicindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -140,7 +140,7 @@ files:
|
|
140
140
|
- lib/rack/musicindex.rb
|
141
141
|
- lib/rack/musicindex/version.rb
|
142
142
|
- rack-musicindex.gemspec
|
143
|
-
- spec/fixtures/foo/test.mp3
|
143
|
+
- spec/fixtures/foo/test foo.mp3
|
144
144
|
- spec/rack/musicindex_spec.rb
|
145
145
|
- spec/spec_helper.rb
|
146
146
|
- spec/test_app.rb
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash: -
|
161
|
+
hash: -1489195418899785487
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
164
164
|
requirements:
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash: -
|
170
|
+
hash: -1489195418899785487
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|
173
173
|
rubygems_version: 1.8.24
|
@@ -175,7 +175,7 @@ signing_key:
|
|
175
175
|
specification_version: 3
|
176
176
|
summary: A Rack middleware to publish directries containing media files as podcast
|
177
177
|
test_files:
|
178
|
-
- spec/fixtures/foo/test.mp3
|
178
|
+
- spec/fixtures/foo/test foo.mp3
|
179
179
|
- spec/rack/musicindex_spec.rb
|
180
180
|
- spec/spec_helper.rb
|
181
181
|
- spec/test_app.rb
|