diff --git a/internal/plugin/musify.go b/internal/plugin/musify.go index ca91620..29e3ed0 100644 --- a/internal/plugin/musify.go +++ b/internal/plugin/musify.go @@ -193,9 +193,57 @@ func parseContactContainer(contactContainer *goquery.Selection) []data.MusicObje return res } +func parsePlaylistItem(playlistItem *goquery.Selection) (data.Song, error) { + song := data.Song{} + var err error + + song.Name, _ = playlistItem.Attr("data-name") + + playlistDetails := playlistItem.Find("div.playlist__heading") + if playlistDetails.Length() > 0 { + anchorList := playlistDetails.Find("a") + + if anchorList.Length() >= 2 { + // artists + anchorList.Each(func(i int, artistAnchor *goquery.Selection) { + if i < anchorList.Length()-1 { // all except the last one + if url, exists := artistAnchor.Attr("href"); exists { + song.Artists = append(song.Artists, data.Artist{ + Name: strings.TrimSpace(artistAnchor.Text()), + Sources: []data.Source{ + {Url: musifyHost + url, ObjectType: data.ArtistSource}, + }, + }) + } + } + }) + + // track + trackAnchor := anchorList.Last() + if href, exists := trackAnchor.Attr("href"); exists { + song.Sources = append(song.Sources, data.Source{ + Url: musifyHost + href, + ObjectType: data.SongSource, + }) + } + + } else { + err = errors.New("there are not enough anchors (2) for artist and track") + } + } + + return song, err +} + func parsePlaylist(playlist *goquery.Selection) []data.MusicObject { res := []data.MusicObject{} + playlist.Find("div.playlist__item").Each(func(i int, playlistItem *goquery.Selection) { + if song, err := parsePlaylistItem(playlistItem); err == nil { + res = append(res, song) + } + }) + return res }