mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
fix lastfm extraction regression and honor no-db
This commit is contained in:
@@ -552,6 +552,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() { _ = mainApp.Close() }()
|
||||
mainApp.IgnoreDB = gopts.noDB
|
||||
|
||||
title, tracks, err := fetchLastFMPlaylist(ctx, cfg.Session.Downloads.VerifySSL, opts.PlaylistURL)
|
||||
if err != nil {
|
||||
@@ -1422,12 +1423,13 @@ type resolvedLastFMTrack struct {
|
||||
}
|
||||
|
||||
var (
|
||||
lastFMTitleTagsRe = regexp.MustCompile(`<a\b[^>]*\btitle=(?:"([^"]+)"|'([^']+)')`)
|
||||
lastFMTotalTracksRe = regexp.MustCompile(`data-playlisting-entry-count="(\d+)"`)
|
||||
lastFMPlaylistTitleRe = regexp.MustCompile(`<h1[^>]*class="[^"]*playlisting-playlist-header-title[^"]*"[^>]*>([^<]+)</h1>`)
|
||||
lastFMMirrorTitleRe = regexp.MustCompile(`^Title:\s*(.+?)\s+\|`)
|
||||
lastFMMirrorLinkTextRe = regexp.MustCompile(`\[([^\]]+)\]\(`)
|
||||
errLastFMInvalidSource = "unsupported source"
|
||||
lastFMTitleTagsRe = regexp.MustCompile(`<a\b[^>]*\btitle=(?:"([^"]+)"|'([^']+)')`)
|
||||
lastFMDataTrackArtistRe = regexp.MustCompile(`data-track-name=(?:"([^"]+)"|'([^']+)')[^>]*data-artist-name=(?:"([^"]+)"|'([^']+)')`)
|
||||
lastFMTotalTracksRe = regexp.MustCompile(`data-playlisting-entry-count="(\d+)"`)
|
||||
lastFMPlaylistTitleRe = regexp.MustCompile(`<h1[^>]*class="[^"]*playlisting-playlist-header-title[^"]*"[^>]*>([^<]+)</h1>`)
|
||||
lastFMMirrorTitleRe = regexp.MustCompile(`^Title:\s*(.+?)\s+\|`)
|
||||
lastFMMirrorLinkTextRe = regexp.MustCompile(`\[([^\]]+)\]\(`)
|
||||
errLastFMInvalidSource = "unsupported source"
|
||||
)
|
||||
|
||||
func addURLToQueue(ctx context.Context, mainApp *app.Main, raw string) bool {
|
||||
@@ -1828,11 +1830,30 @@ func extractLastFMPlaylistInfo(page string) (string, int, error) {
|
||||
}
|
||||
|
||||
func extractLastFMTitleArtistPairs(page string) []lastFMTrack {
|
||||
dataPairs := lastFMDataTrackArtistRe.FindAllStringSubmatch(page, -1)
|
||||
if len(dataPairs) > 0 {
|
||||
out := make([]lastFMTrack, 0, len(dataPairs))
|
||||
for _, m := range dataPairs {
|
||||
title := html.UnescapeString(strings.TrimSpace(firstNonEmpty(m[1], m[2])))
|
||||
artist := html.UnescapeString(strings.TrimSpace(firstNonEmpty(m[3], m[4])))
|
||||
if title == "" || artist == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, lastFMTrack{Title: title, Artist: artist})
|
||||
}
|
||||
if len(out) > 0 {
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
titles := lastFMTitleTagsRe.FindAllStringSubmatch(page, -1)
|
||||
out := make([]lastFMTrack, 0, len(titles)/2)
|
||||
for i := 0; i+1 < len(titles); i += 2 {
|
||||
titleRaw := strings.TrimSpace(firstNonEmpty(titles[i][1], titles[i][2]))
|
||||
artistRaw := strings.TrimSpace(firstNonEmpty(titles[i+1][1], titles[i+1][2]))
|
||||
if strings.EqualFold(titleRaw, "Play on YouTube") || strings.EqualFold(artistRaw, "Play on YouTube") {
|
||||
continue
|
||||
}
|
||||
title := html.UnescapeString(titleRaw)
|
||||
artist := html.UnescapeString(artistRaw)
|
||||
if title == "" || artist == "" {
|
||||
|
||||
Reference in New Issue
Block a user