-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_tube_app.rb
90 lines (59 loc) · 1.55 KB
/
simple_tube_app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
# simple_tube_app.rb
# Copyright 2014 Robert Jones ([email protected]) Craic Computing LLC
# This code and associated data files are distributed freely under the terms of the MIT license
# Sinatra wrapper script that embeds a youtube video in a clean simple page without all the comments etc
require 'erb'
require 'open-uri'
# require 'json'
# require 'yaml'
$:.unshift File.join(File.dirname(__FILE__))
class SimpleTubeApp < Sinatra::Base
# def self.get_or_post(url,&block)
# get(url,&block)
# post(url,&block)
# end
set :root, File.dirname(__FILE__)
root_dir = File.dirname(__FILE__)
set :static, true
disable :show_exceptions
not_found do
erb '404'.to_sym
end
get '/' do
erb :index
end
get '/about' do
erb :about
end
# get '/index' do
# video_id = params[:id]
# erb :index
# end
# Embed a youtube video
get '/watch' do
# @base_url = 'https://www.youtube.com/watch?v='
@youtube_id = ''
if params[:v] =~ /v\=(\S+)/
id = $1
# strip off any other args is there are any
if id =~ /^([^\&\#]+)/
id = $1
end
@youtube_id = id
else
# just the id code - ? allow this or require the full URL
@youtube_id = params[:v]
end
STDERR.puts @youtube_id
# STDERR.puts params[:bgcolor]
# # optional params
# @bgcolor = '#222'
# if params[:bgcolor] and params[:bgcolor] =~ /^[0-9a-f][0-9a-f][0-9a-f]/
# @bgcolor = '#' + params[:bgcolor]
# end
# STDERR.puts @bgcolor
# size
erb :watch
end
end