func main() { var conf Conf err := envdecode.Decode(&conf) if err != nil { log.Fatal(err.Error()) } client := wgt2.GetSpotifyClient(conf.ClientID, conf.ClientSecret, conf.RefreshToken) db, err := wgt2.LoadDatabase(DBFilename) if err != nil { log.Fatal(err.Error()) } user, err := client.CurrentUser() if err != nil { log.Fatal(err.Error()) } var trackIDs []spotify.ID // // Main playlist // trackIDs = nil for _, artist := range db.Artists.Data { bound := TracksPerArtist if bound > len(artist.TopTracks) { bound = len(artist.TopTracks) } for _, track := range artist.TopTracks[0:bound] { trackIDs = append(trackIDs, spotify.ID(track.ID)) } } dbPlaylist, err := updatePlaylist(client, user, PlaylistName, trackIDs) if err != nil { log.Fatal(err.Error()) } db.Playlists.AddPlaylist(dbPlaylist) // // Popular playlist // trackIDs = nil for _, artist := range db.Artists.Data { // an arbitrary threshold if artist.Popularity < 20 { continue } bound := TracksPerArtist if bound > len(artist.TopTracks) { bound = len(artist.TopTracks) } for _, track := range artist.TopTracks[0:bound] { trackIDs = append(trackIDs, spotify.ID(track.ID)) } } dbPlaylist, err = updatePlaylist(client, user, PlaylistNamePopular, trackIDs) if err != nil { log.Fatal(err.Error()) } db.Playlists.AddPlaylist(dbPlaylist) // // Obscure playlist // trackIDs = nil for _, artist := range db.Artists.Data { // an arbitrary threshold if artist.Popularity >= 20 { continue } bound := TracksPerArtist if bound > len(artist.TopTracks) { bound = len(artist.TopTracks) } for _, track := range artist.TopTracks[0:bound] { trackIDs = append(trackIDs, spotify.ID(track.ID)) } } dbPlaylist, err = updatePlaylist(client, user, PlaylistNameObscure, trackIDs) if err != nil { log.Fatal(err.Error()) } db.Playlists.AddPlaylist(dbPlaylist) err = db.Save() if err != nil { log.Fatal(err.Error()) } }
func main() { var conf Conf err := envdecode.Decode(&conf) if err != nil { log.Fatal(err.Error()) } client := wgt2.GetSpotifyClient(conf.ClientID, conf.ClientSecret, conf.RefreshToken) db, err := wgt2.LoadDatabase(DBFilename) if err != nil { log.Fatal(err.Error()) } for _, rawArtist := range db.RawArtists.Data { dbArtist := db.Artists.GetArtistByWGTName(rawArtist.WGTName) if dbArtist != nil { log.Printf("Have artist already: %v", dbArtist.Name) continue } searchName := rawArtist.WGTName if val, ok := ManualOverrides[searchName]; ok { if val == "" { log.Printf("Skipping '%v' due to override", searchName) continue } log.Printf("Using manual override '%v' for '%v'", val, searchName) searchName = val } res, err := client.Search(searchName, spotify.SearchTypeArtist) if err != nil { log.Fatal(err.Error()) } if len(res.Artists.Artists) < 1 { log.Printf("Artist not found: %v", rawArtist.WGTName) continue } artist := res.Artists.Artists[0] dbArtist = &wgt2.Artist{ Genres: artist.Genres, ID: string(artist.ID), Name: artist.Name, Popularity: artist.Popularity, URI: string(artist.URI), WGTName: rawArtist.WGTName, } log.Printf("Found artist: %v (from: %v; popularity: %v/100)", artist.Name, rawArtist.WGTName, artist.Popularity) tracks, err := client.GetArtistsTopTracks(artist.ID, "US") if err != nil { log.Fatal(err.Error()) } for _, track := range tracks { dbTrack := wgt2.Track{ ID: string(track.ID), Name: track.Name, Popularity: track.Popularity, URI: string(track.URI), } dbArtist.TopTracks = append(dbArtist.TopTracks, dbTrack) } db.Artists.AddArtist(dbArtist) } err = db.Save() if err != nil { log.Fatal(err.Error()) } }