-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
102 lines (78 loc) · 1.91 KB
/
handlers.go
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
package main
import (
"github.com/gorilla/mux"
"net/http"
)
func index(w http.ResponseWriter, req *http.Request) {
_ = req.URL.Path
p := Page{
Title: "Home",
}
err := tmpl.ExecuteTemplate(w, "home.gohtml", p)
check(err, w)
}
func movieHandler(w http.ResponseWriter, req *http.Request) {
p := Page{
Title: "Movies",
MediaTitleAndLink: movies,
}
err := tmpl.ExecuteTemplate(w, "movieIndex.gohtml", p)
check(err, w)
}
func showsHandler(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
var p Page
var title string
if vars["show"] == "" {
var m = map[string]string{}
for show := range shows {
m[show] = "/shows/" + show
}
p = Page{
Title: "Shows",
MediaTitleAndLink: m,
}
} else if vars["season"] == "" {
var m = map[string]string{}
for season := range shows[vars["show"]] {
if season == vars["show"] {
continue
}
m[season] = "/shows/" + vars["show"] + "/" + season
}
title = vars["show"]
p = Page{
Title: title,
MediaTitleAndLink: m,
}
} else if vars["episode"] == "" {
var m = map[string]string{}
for episode := range shows[vars["show"]][vars["season"]] {
m[episode] = "/view/" + vars["show"] + "/" + vars["season"] + "/" + episode
}
title = vars["show"] + " | " + vars["season"]
p = Page{
Title: title,
MediaTitleAndLink: m,
}
}
err := tmpl.ExecuteTemplate(w, "movieIndex.gohtml", p)
check(err, w)
}
func movieViewerHandler(w http.ResponseWriter, req *http.Request) {
var url, title string
vars := mux.Vars(req)
if vars["season"] == "" {
url = "/files/movies/" + vars["movieOrShow"]
title = vars["movieOrShow"]
} else {
url = "/files/shows/" + vars["movieOrShow"] + "/" + vars["season"] + "/" + vars["episode"]
title = vars["movieOrShow"]
}
p := Page{
Title: title,
MediaSrc: url,
}
err := tmpl.ExecuteTemplate(w, "viewer.gohtml", p)
check(err, w)
}