summaryrefslogtreecommitdiff
path: root/app/app.go
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2020-03-25 16:22:41 +1000
committerJames Mills <prologic@shortcircuit.net.au>2020-03-25 16:22:41 +1000
commit9fa34273082e588f8876c4f4d1f658f4b3590e92 (patch)
tree3b99fc82d67b857e9dbe747d1bfc330aa21995e9 /app/app.go
parent2c8af031648d110148dfe672c4fc3063f1743374 (diff)
Add trending and ability to sort playlist by views
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/app.go b/app/app.go
index 71ef0d7..6c56540 100644
--- a/app/app.go
+++ b/app/app.go
@@ -162,7 +162,7 @@ func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("/")
pl := a.Library.Playlist()
if len(pl) > 0 {
- http.Redirect(w, r, "/v/"+pl[0].ID, 302)
+ http.Redirect(w, r, fmt.Sprintf("/v/%s?%s", pl[0].ID, r.URL.RawQuery), 302)
} else {
ctx := &struct {
Playing *media.Video
@@ -312,6 +312,13 @@ func (a *App) pageHandler(w http.ResponseWriter, r *http.Request) {
video.Views = views
}
+ if r.URL.Query().Get("trending") != "" {
+ log.Info("sorting by trending")
+ media.By(media.SortByViews).Sort(playlist)
+ } else {
+ media.By(media.SortByTimestamp).Sort(playlist)
+ }
+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
ctx := &struct {
Playing *media.Video