update(bandcamp): avoid duplications (close #5)

This commit is contained in:
rick 2021-09-12 01:41:54 +02:00
parent a69da12bf8
commit d6616573e2
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 58 additions and 18 deletions

View file

@ -125,34 +125,31 @@ func getListPlaylist(id, token, tokentype string) {
playlist := getAllTracksPlaylist(token, tokentype, id, 0)
var find bool
var tmp string
var tmp, artist, album, urlSpotify string
var MyResp = &RespBandcamp{}
MyResp.Todo = len(playlist.Items)
MyResp.Done = 0
Queue[token] = MyResp
for i := 0; i < len(playlist.Items); i++ {
find, tmp = searchAlbumBandcamp(playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.Artists[0].Name)
album = playlist.Items[i].Track.Album.Name
artist = playlist.Items[i].Track.Album.Artists[0].Name
urlSpotify = playlist.Items[i].Track.Album.ExternalUrls.Spotify
if (MyResp.ContainsAlbum(album, artist)) {
MyResp.Todo--
continue
}
find, tmp = searchAlbumBandcamp(album, artist)
if find {
MyResp.AddAlbum(newUrlBandcamp(
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
tmp))
MyResp.AddAlbum(newUrlBandcamp(artist, album, urlSpotify, tmp))
} else {
find, tmp = searchArtistBandcamp(playlist.Items[i].Track.Album.Artists[0].Name)
find, tmp = searchArtistBandcamp(artist)
if find {
MyResp.AddArtist(newUrlBandcamp(
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
tmp))
MyResp.AddArtist(newUrlBandcamp(artist, album, urlSpotify, tmp))
} else {
MyResp.AddNotfound(newUrlWoBandcamp(
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify))
MyResp.AddNotfound(newUrlWoBandcamp(artist, album, urlSpotify))
}
}

View file

@ -33,7 +33,50 @@ type RespBandcamp struct {
Albums []UrlBandcamp `json:"albums"`
Artists []UrlBandcamp `json:"artists"`
Notfound []UrlBandcamp `json:"notfound"`
}
func (rp *RespBandcamp) ContainsAlbum(album, artist string) bool {
ret := false
for _, elem := range rp.Albums {
if elem.Album == album && elem.Artiste == artist {
ret = true
break
}
}
if !ret {
for _, elem := range rp.Artists {
if elem.Album == album && elem.Artiste == artist {
ret = true
break
}
}
}
if !ret {
for _, elem := range rp.Notfound {
if elem.Album == album && elem.Artiste == artist {
ret = true
break
}
}
}
return ret
}
func (rp *RespBandcamp) ContainsArtist(artist string) bool {
ret := false
for _, elem := range rp.Artists {
if elem.Artiste == artist {
ret = true
break
}
}
return ret
}
func (rp *RespBandcamp) AddAlbum(tmp UrlBandcamp) []UrlBandcamp {