enabling gos comression negotiation
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/common"
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/scraper"
|
||||
)
|
||||
|
||||
func extractName(s string) string {
|
||||
@@ -17,6 +21,7 @@ func extractName(s string) string {
|
||||
}
|
||||
|
||||
type Musify struct {
|
||||
session *scraper.Session
|
||||
}
|
||||
|
||||
func (m Musify) Name() string {
|
||||
@@ -36,16 +41,51 @@ func (m Musify) RegexAlbum() *regexp.Regexp {
|
||||
}
|
||||
|
||||
func (m *Musify) Init() {
|
||||
|
||||
m.session = scraper.NewSession()
|
||||
}
|
||||
|
||||
func (m Musify) RegexSong() *regexp.Regexp {
|
||||
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
|
||||
}
|
||||
|
||||
func (m Musify) Search(query common.Query) ([]data.MusicObject, error) {
|
||||
res := []data.MusicObject{}
|
||||
return res, nil
|
||||
func (m *Musify) Search(query common.Query) ([]data.MusicObject, error) {
|
||||
musicObjects := []data.MusicObject{}
|
||||
|
||||
resp, err := m.session.PostMultipartForm("https://musify.club/en/search", map[string]string{
|
||||
"SearchText": query.Search, // alternatively I could also add year and genre
|
||||
})
|
||||
if err != nil {
|
||||
return musicObjects, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
var bodyReader io.Reader = resp.Body
|
||||
|
||||
// Check if we need to decompress manually
|
||||
if resp.Header.Get("Content-Encoding") == "gzip" && false {
|
||||
fmt.Println("Response is gzipped, decompressing...")
|
||||
gzReader, err := gzip.NewReader(resp.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer gzReader.Close()
|
||||
bodyReader = gzReader
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(bodyReader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Response length: %d bytes\n", len(body))
|
||||
fmt.Println("Content:")
|
||||
fmt.Println(string(body))
|
||||
|
||||
fmt.Println(resp.Header)
|
||||
fmt.Println(resp.StatusCode)
|
||||
|
||||
return musicObjects, nil
|
||||
}
|
||||
|
||||
func (m Musify) FetchSong(source data.Source) (data.Song, error) {
|
||||
|
||||
Reference in New Issue
Block a user