-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (55 loc) · 1.75 KB
/
main.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
package main
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
"os"
"github.com/gorilla/mux"
)
const (
mediaDirectory = "./media"
moviesDirectory = "./media/movies/."
//showsDirectory = "./media/shows/"
)
var movies = map[string]string{}
var shows = map[string]map[string]map[string]string{}
type Page struct {
Title string
MediaTitleAndLink map[string]string
MediaSrc string
}
var tmpl *template.Template
func init() {
fmt.Print("[+] Parsing templates...")
tmpl = template.Must(template.ParseGlob("./temp/*.gohtml"))
fmt.Print(" Done\n")
fmt.Print("[+] Gathering Movie Map...")
movies = GetMediaInformation(moviesDirectory)
fmt.Print(" Done\n")
fmt.Print("[+] Gathering Show Map...")
GetShowInfo()
fmt.Print(" Done\n")
}
func main() {
fmt.Println("[+] Serving at localhost:8080")
r := mux.NewRouter()
r.HandleFunc("/shows", showsHandler)
r.HandleFunc("/shows/", showsHandler)
r.HandleFunc("/shows/{show}", showsHandler)
r.HandleFunc("/shows/{show}/", showsHandler)
r.HandleFunc("/shows/{show}/{season}", showsHandler)
r.HandleFunc("/shows/{show}/{season}/", showsHandler)
r.HandleFunc("/shows/{show}/{season}/{episode}", movieViewerHandler)
r.HandleFunc("/shows/{show}/{season}/{episode}/", movieViewerHandler)
r.HandleFunc("/movies", movieHandler)
r.HandleFunc("/movies/", movieHandler)
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
r.PathPrefix("/files/").Handler(http.StripPrefix("/files/", http.FileServer(http.Dir(mediaDirectory))))
r.HandleFunc("/view/{movieOrShow}/{season}/{episode}", movieViewerHandler)
r.HandleFunc("/view/{movieOrShow}", movieViewerHandler)
r.HandleFunc("/", index)
http.ListenAndServe(":8080", r)
}