|
@@ -18,6 +18,7 @@ func Router(c *movies.Collection) http.HandlerFunc {
|
18
|
18
|
movieHandler := Movie(c)
|
19
|
19
|
listHandler := List(c)
|
20
|
20
|
filesHandler := Files(c)
|
|
21
|
+ fileHandler := File(c, "/files/")
|
21
|
22
|
|
22
|
23
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
23
|
24
|
path := r.URL.Path
|
|
@@ -25,9 +26,6 @@ func Router(c *movies.Collection) http.HandlerFunc {
|
25
|
26
|
case path == "/":
|
26
|
27
|
homeHandler(w, r)
|
27
|
28
|
return
|
28
|
|
- case path == "/files":
|
29
|
|
- filesHandler(w, r)
|
30
|
|
- return
|
31
|
29
|
case path == "/style.css":
|
32
|
30
|
http.ServeFile(w, r, "templates/style.css")
|
33
|
31
|
return
|
|
@@ -37,6 +35,12 @@ func Router(c *movies.Collection) http.HandlerFunc {
|
37
|
35
|
case strings.HasPrefix(path, "/tt"):
|
38
|
36
|
movieHandler(w, r)
|
39
|
37
|
return
|
|
38
|
+ case path == "/files":
|
|
39
|
+ filesHandler(w, r)
|
|
40
|
+ return
|
|
41
|
+ case strings.HasPrefix(path, "/files/"):
|
|
42
|
+ fileHandler(w, r)
|
|
43
|
+ return
|
40
|
44
|
}
|
41
|
45
|
})
|
42
|
46
|
}
|
|
@@ -53,7 +57,7 @@ func Home(c *movies.Collection) http.HandlerFunc {
|
53
|
57
|
|
54
|
58
|
if r.Method == "POST" {
|
55
|
59
|
if r.FormValue("omdb_json") != "" {
|
56
|
|
- m, err := movies.Unmarshal([]byte(r.FormValue("omdb_json")))
|
|
60
|
+ m, err := movies.UnmarshalFromOMDB([]byte(r.FormValue("omdb_json")))
|
57
|
61
|
if err != nil {
|
58
|
62
|
w.WriteHeader(http.StatusBadRequest)
|
59
|
63
|
errs = append(errs, err)
|
|
@@ -79,12 +83,14 @@ func Home(c *movies.Collection) http.HandlerFunc {
|
79
|
83
|
}
|
80
|
84
|
}
|
81
|
85
|
|
82
|
|
- t.Execute(w, map[string]interface{}{
|
|
86
|
+ if err := t.Execute(w, map[string]interface{}{
|
83
|
87
|
"Collection": c,
|
84
|
88
|
"IMDBID": r.URL.Query().Get("imdb_id"),
|
85
|
89
|
"OMDBString": omdbString,
|
86
|
90
|
"Errors": errs,
|
87
|
|
- })
|
|
91
|
+ }); err != nil {
|
|
92
|
+ fmt.Println(err)
|
|
93
|
+ }
|
88
|
94
|
})
|
89
|
95
|
}
|
90
|
96
|
|
|
@@ -121,14 +127,25 @@ func Movie(c *movies.Collection) http.HandlerFunc {
|
121
|
127
|
errs = append(errs, fmt.Errorf("you cannot change the imdb id."))
|
122
|
128
|
} else {
|
123
|
129
|
m = updated
|
|
130
|
+ fmt.Println("Update with", m)
|
124
|
131
|
c.Update(updated)
|
125
|
132
|
}
|
126
|
133
|
}
|
127
|
134
|
|
128
|
135
|
if files := r.FormValue("files"); files != "" {
|
|
136
|
+ files = strings.ReplaceAll(files, "\r", "")
|
129
|
137
|
m.Files = strings.Split(files, "\n")
|
|
138
|
+ fmt.Println("Update with", m)
|
130
|
139
|
c.Update(m)
|
131
|
140
|
}
|
|
141
|
+
|
|
142
|
+ if r.FormValue("generate_mediainfo") != "" {
|
|
143
|
+ if err := m.GenerateMediaInfo(); err != nil {
|
|
144
|
+ errs = append(errs, err)
|
|
145
|
+ } else {
|
|
146
|
+ c.Update(m)
|
|
147
|
+ }
|
|
148
|
+ }
|
132
|
149
|
}
|
133
|
150
|
|
134
|
151
|
fileQuery := r.URL.Query().Get("file_query")
|
|
@@ -142,14 +159,16 @@ func Movie(c *movies.Collection) http.HandlerFunc {
|
142
|
159
|
errs = append(errs, err)
|
143
|
160
|
}
|
144
|
161
|
|
145
|
|
- t.Execute(w, map[string]interface{}{
|
|
162
|
+ if err := t.Execute(w, map[string]interface{}{
|
146
|
163
|
"Movie": m,
|
147
|
164
|
"MovieJSON": string(b),
|
148
|
165
|
"Files": strings.Join(m.Files, "\n"),
|
149
|
166
|
"FileQuery": fileQuery,
|
150
|
167
|
"FileResults": fileResults,
|
151
|
168
|
"Errors": errs,
|
152
|
|
- })
|
|
169
|
+ }); err != nil {
|
|
170
|
+ fmt.Println(err)
|
|
171
|
+ }
|
153
|
172
|
})
|
154
|
173
|
}
|
155
|
174
|
|
|
@@ -200,7 +219,7 @@ func List(c *movies.Collection) http.HandlerFunc {
|
200
|
219
|
}
|
201
|
220
|
}
|
202
|
221
|
|
203
|
|
- t.Execute(w, map[string]interface{}{
|
|
222
|
+ if err := t.Execute(w, map[string]interface{}{
|
204
|
223
|
"List": l,
|
205
|
224
|
"Description": template.HTML(
|
206
|
225
|
blackfriday.Run(
|
|
@@ -209,7 +228,9 @@ func List(c *movies.Collection) http.HandlerFunc {
|
209
|
228
|
"Movies": ms,
|
210
|
229
|
"ListJSON": string(b),
|
211
|
230
|
"Errors": errs,
|
212
|
|
- })
|
|
231
|
+ }); err != nil {
|
|
232
|
+ fmt.Println(err)
|
|
233
|
+ }
|
213
|
234
|
})
|
214
|
235
|
}
|
215
|
236
|
|
|
@@ -238,9 +259,19 @@ func Files(c *movies.Collection) http.HandlerFunc {
|
238
|
259
|
}
|
239
|
260
|
}
|
240
|
261
|
|
241
|
|
- t.Execute(w, map[string]interface{}{
|
|
262
|
+ if err := t.Execute(w, map[string]interface{}{
|
242
|
263
|
"Files": c.AllFiles(),
|
243
|
264
|
"Errors": errs,
|
244
|
|
- })
|
|
265
|
+ }); err != nil {
|
|
266
|
+ fmt.Println(err)
|
|
267
|
+ }
|
|
268
|
+ })
|
|
269
|
+}
|
|
270
|
+
|
|
271
|
+func File(c *movies.Collection, prefix string) http.HandlerFunc {
|
|
272
|
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
273
|
+ file := "/" + strings.TrimPrefix(r.URL.Path, prefix)
|
|
274
|
+
|
|
275
|
+ c.Files.Serve(w, r, file)
|
245
|
276
|
})
|
246
|
277
|
}
|