feat(media): fallback to lower quality if requested format is unavailable
This commit is contained in:
@@ -98,10 +98,8 @@ func (c *Client) FetchMedia(ctx context.Context, song *Song, quality string) (*M
|
||||
case "mp3_128":
|
||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"MP3_128"}]`
|
||||
case "mp3_320":
|
||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"MP3_320"}]`
|
||||
case "flac":
|
||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"FLAC"}]`
|
||||
case "best":
|
||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"MP3_320"},{"cipher":"BF_CBC_STRIPE","format":"MP3_128"}]`
|
||||
case "flac", "best":
|
||||
formats = `[{"cipher":"BF_CBC_STRIPE","format":"FLAC"},{"cipher":"BF_CBC_STRIPE","format":"MP3_320"},{"cipher":"BF_CBC_STRIPE","format":"MP3_128"}]`
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,7 @@ func (m *Media) GetURL() (string, error) {
|
||||
return "", fmt.Errorf("no media sources found")
|
||||
}
|
||||
|
||||
url := m.Data[0].Media[0].Sources[0].URL
|
||||
for _, source := range m.Data[0].Media[0].Sources {
|
||||
if source.Provider == "ak" {
|
||||
url = source.URL
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return url, nil
|
||||
return m.Data[0].Media[0].Sources[0].URL, nil
|
||||
}
|
||||
|
||||
func (m *Media) GetFormat() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user