-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
38 lines (33 loc) · 836 Bytes
/
app.rb
File metadata and controls
38 lines (33 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require_relative 'deps'
require 'sinatra'
class App < Sinatra::Base
def base_url(request, path)
(request.url.split('/').first(3) + [path]).join('/')
end
get '/feeds/videos.xml' do
podcast = youtube
.get
&.parse
&.generate_podcast(
request.url,
episode_base_url,
params.fetch("filter", {})
)&.to_xml
content_type youtube.content_type
status youtube.code
podcast || youtube.body
end
get '/listen' do
video = Cache.find_or_create_video(params[:v])
if video.audio_path
content_type video.audio_mime_type
stream do |body|
video.each_audio_chunk { |c| body << c }
end
else
status 500
content_type "text/plain"
video.download_log
end
end
end