forked from caseywatts/youtubesets
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathyoutubesets.rb
More file actions
110 lines (84 loc) · 2.61 KB
/
youtubesets.rb
File metadata and controls
110 lines (84 loc) · 2.61 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require "sinatra"
#To get this next line to work, run gem install sinatra-contrib first
require "sinatra/reloader" if development?
configure do
enable :sessions
end
helpers do
def randomvideo(set)
set.sample
end
#We're trying not to use the rest of these helpers any more, but they're here to make the pmj code below still work for comparison
def embedyoutube(videonumber)
%{
<body style="margin:0;">
<object height="100%" width="100%"><param name="movie" value="http://www.youtube.com/v/#{videonumber}&autoplay=1" /><embed height="100%" src="http://www.youtube.com/v/#{videonumber}&autoplay=1" type="application/x-shockwave-flash" width="100%"></embed></object>
</body>
}
end
def beyoncevideos
["QczgvUDskk0", "VBmMU_iwe6U", "Vjw92oUduEM", "4m1EFMoRFvY", "FHp2KgyQUFk"]
end
def pmjvideos
["pXYWDtXbBB0", "VBmCJEehYtU", "GZQJrM09jbU"]
end
end
##INDEX
##Main Welcome Page
get '/' do
erb :index
#"<h1>Hi!</h1><h2>If you know the url you can play a random video from set of youtube videos!</h2>"
end
##Display the Video Sets, old-style where the videos are hard coded above
get '/beyonce' do
#embedyoutube(randomvideo(beyoncevideos))
@videonumber = randomvideo(beyoncevideos)
erb :play
end
get '/pmj' do
embedyoutube(randomvideo(pmjvideos))
end
##New, RESTful code
##NEW page
get '/sets/new' do
erb :new
end
##Create page
post "/sets" do
"Success!"
#This should include more
end
##not the RESTful new page with the form we want, but a parameters way to make a new video set
get '/sets/new/:setname/:videonumber' do |setname, videonumber|
#setname = "pharrell"
#videonumber = "y6Sxv-sUYtM"
session[setname] = [videonumber]
"Video " + videonumber + "is now the only video in setname " + setname
end
get '/sets/add/:setname/:videonumber' do |setname, videonumber|
session[setname] << videonumber
"Video " + videonumber + "has been added to set " + setname
end
##Play the Pharrell video set - not necessary eventually, just for testing
get '/sets/pharrell' do
@videonumber = randomvideo(session["pharrell"])
#@videonumber = "y6Sxv-sUYtM"
erb :play
end
#Session page for troubleshooting the session
get '/session' do
session[:sessiontestvariable] = 3.14
session.inspect
end
##example of sinatra input by url parameters
##The ?var=1&var2=2&var3=3 style works too, but Sinatra can give us prettier url parameters
get '/params/:idlol' do
params.inspect
end
get '/favorite/:fruit' do |fruit|
"My favorite fruit is the " + fruit.to_s
#params["fruit"] also works instead of fruit
end
get '/add/:num1/:num2' do |num1, num2|
##your code here, as an example
end