Add basic html player

This commit is contained in:
nxshock 2022-07-02 16:20:06 +05:00
parent c58742d186
commit 960485d260
4 changed files with 1307 additions and 2 deletions

View File

@ -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{}

View File

@ -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 {

View File

@ -15,8 +15,8 @@
<main>
<h1>Список жанров</h1>
<ul id="genres-list">
<li><a href="/getm3u?top100=1">TOP 100</a></li>{{range .Genres}}
<li><a href="/getm3u?genre={{.Code}}">{{.Name}}</a></li>{{end}}
<li><a href="/player?top100=1">TOP 100</a></li>{{range .Genres}}
<li><a href="/player?genre={{.Code}}">{{.Name}}</a></li>{{end}}
</ul>
</main>
</body>

1266
templates/player.htm Normal file

File diff suppressed because it is too large Load Diff