-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
63 lines (56 loc) · 1.77 KB
/
main.rb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'rubygems'
require 'bundler/setup'
require 'airvideo-ng'
require 'sinatra'
require "base64"
configure do
server_host = 'something.dyndns.org'
server_port = 45631
server_password = 'YOUR_PASSWORD'
raise "You have to enter your server data in the script" if server_host == 'something.dyndns.org'
$airvideo = AirVideo::Client.new(server_host,server_port,server_password)
$airvideo.max_width = 640
$airvideo.max_height = 480
end
get '/' do
$airvideo.cd('/')
items = $airvideo.ls
@folders = items.select{|item| item.is_a? AirVideo::Client::FolderObject}
@videos = items.select{|item| item.is_a? AirVideo::Client::VideoObject}
erb :index
end
get '/folder/:folder_location' do
path = Base64.decode64(params[:folder_location])
$airvideo.cd(path)
items = $airvideo.ls
@folders = items.select{|item| item.is_a? AirVideo::Client::FolderObject}
@videos = items.select{|item| item.is_a? AirVideo::Client::VideoObject}
erb :index
end
get '/play/:video_location/:playback_mode/:bitrate' do
playback_mode = params[:playback_mode]
bitrate = params[:bitrate]
video_location = Base64.decode64(params[:video_location])
video_dir = video_location.split('/')[0..-2].join('/') + "/"
video_name = video_location.split('/').last
$airvideo.cd(video_dir)
video_file = $airvideo.ls.select{|item| item.name == video_name}.first
case playback_mode
when 'native'
@video_live_url = video_file.url
when 'convert'
already_retried = false
begin
@video_live_url = video_file.live_url + "?q=#{bitrate}"
rescue
unless already_retried
already_retried = true
retry
end
return "Airvideo can't convert this file, sorry"
end
else
raise 'unknown playback mode: #{playback_mode.inspect}'
end
erb :play
end