mirror of
https://github.com/nxshock/promodj.git
synced 2024-11-27 03:01:01 +05:00
Add basic html player
This commit is contained in:
parent
c58742d186
commit
960485d260
38
handlers.go
38
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{}
|
||||
|
1
main.go
1
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 {
|
||||
|
@ -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
1266
templates/player.htm
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user