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) playlist := getAllTracksPlaylist(token, tokentype, id, 0)
var find bool var find bool
var tmp string var tmp, artist, album, urlSpotify string
var MyResp = &RespBandcamp{} var MyResp = &RespBandcamp{}
MyResp.Todo = len(playlist.Items) MyResp.Todo = len(playlist.Items)
MyResp.Done = 0 MyResp.Done = 0
Queue[token] = MyResp Queue[token] = MyResp
for i := 0; i < len(playlist.Items); i++ { for i := 0; i < len(playlist.Items); i++ {
find, tmp = searchAlbumBandcamp(playlist.Items[i].Track.Album.Name, album = playlist.Items[i].Track.Album.Name
playlist.Items[i].Track.Album.Artists[0].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 { if find {
MyResp.AddAlbum(newUrlBandcamp( MyResp.AddAlbum(newUrlBandcamp(artist, album, urlSpotify, tmp))
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
tmp))
} else { } else {
find, tmp = searchArtistBandcamp(playlist.Items[i].Track.Album.Artists[0].Name) find, tmp = searchArtistBandcamp(artist)
if find { if find {
MyResp.AddArtist(newUrlBandcamp( MyResp.AddArtist(newUrlBandcamp(artist, album, urlSpotify, tmp))
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify,
tmp))
} else { } else {
MyResp.AddNotfound(newUrlWoBandcamp( MyResp.AddNotfound(newUrlWoBandcamp(artist, album, urlSpotify))
playlist.Items[i].Track.Album.Artists[0].Name,
playlist.Items[i].Track.Album.Name,
playlist.Items[i].Track.Album.ExternalUrls.Spotify))
} }
} }

View file

@ -33,7 +33,50 @@ type RespBandcamp struct {
Albums []UrlBandcamp `json:"albums"` Albums []UrlBandcamp `json:"albums"`
Artists []UrlBandcamp `json:"artists"` Artists []UrlBandcamp `json:"artists"`
Notfound []UrlBandcamp `json:"notfound"` 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 { func (rp *RespBandcamp) AddAlbum(tmp UrlBandcamp) []UrlBandcamp {