1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package api
- import (
- "encoding/json"
- "net/http"
- "github.com/JamZYM/biliMusic/download"
- )
- func ApiInfo(w http.ResponseWriter, r *http.Request) {
- r.ParseForm()
- bv := r.Form.Get("bv")
- info := download.MusicInfo(bv)
- jsonData, err := json.Marshal(info)
- if err != nil {
- panic(err)
- }
- w.Header().Set("Content-Type", "application/json")
- w.Write(jsonData)
- }
- func ApiDownload(w http.ResponseWriter, r *http.Request) {
- r.ParseForm()
- bv := r.Form.Get("bv")
- title := r.Form.Get("title")
- url_list := download.MusicUrl(bv)
- result := download.MusicDownload(url_list, title)
- if result {
- w.Write([]byte("success"))
- return
- } else {
- w.Write([]byte("fail"))
- return
- }
- }
- func StartServer() {
- http.HandleFunc("/api/download", ApiDownload)
- http.HandleFunc("/api/info", ApiInfo)
- http.ListenAndServe(":5000", nil)
- }
|