diff --git a/handlers.go b/handlers.go
index 2787b41..92d3b32 100644
--- a/handlers.go
+++ b/handlers.go
@@ -26,6 +26,44 @@ func handleGenres(w http.ResponseWriter, r *http.Request) {
}
}
+func handlePlayer(w http.ResponseWriter, r *http.Request) {
+ genreCode := r.FormValue("genre")
+ params := url.Values{}
+
+ if r.FormValue("top100") != "" {
+ params.Set("top100", "1")
+ }
+
+ tracks, err := tracksByGenre(genreCode, params)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ type J struct {
+ Title string
+ File string
+ }
+
+ var data []J
+
+ for _, track := range tracks {
+ host := "music.nxshock.me"
+
+ u, _ := url.Parse(fmt.Sprintf("https://%s/stream", host))
+ q := make(url.Values)
+ q.Add("url", track.Url)
+ u.RawQuery = q.Encode()
+
+ data = append(data, J{track.Title, u.String()})
+ }
+
+ err = templates.Lookup("player.htm").Execute(w, data)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+}
+
func handleGetM3u(w http.ResponseWriter, r *http.Request) {
genreCode := r.FormValue("genre")
params := url.Values{}
diff --git a/main.go b/main.go
index 322023f..52dab36 100644
--- a/main.go
+++ b/main.go
@@ -38,6 +38,7 @@ func main() {
http.HandleFunc("/genres", handleGenres)
http.HandleFunc("/getm3u", handleGetM3u)
http.HandleFunc("/stream", handleStream)
+ http.HandleFunc("/player", handlePlayer)
err := http.ListenAndServe(config.ListenAddr, nil)
if err != nil {
diff --git a/templates/index.htm b/templates/index.htm
index 4771000..266dc61 100644
--- a/templates/index.htm
+++ b/templates/index.htm
@@ -15,8 +15,8 @@
Список жанров
diff --git a/templates/player.htm b/templates/player.htm new file mode 100644 index 0000000..1ac8d95 --- /dev/null +++ b/templates/player.htm @@ -0,0 +1,1266 @@ + + + +
+ +
+ + + + + + +
+ +