Ejemplo n.º 1
0
func (spotify *Spotify) artistAlbums(artist *sconsify.Artist) {
	if simpleAlbumPage, err := spotify.client.GetArtistAlbums(webspotify.ID(artist.GetSpotifyID())); err == nil {
		folder := sconsify.InitFolder(artist.URI, "*"+artist.Name, make([]*sconsify.Playlist, 0))

		if fullTracks, err := spotify.client.GetArtistsTopTracks(webspotify.ID(artist.GetSpotifyID()), "GB"); err == nil {
			tracks := make([]*sconsify.Track, len(fullTracks))
			for i, track := range fullTracks {
				tracks[i] = sconsify.InitWebApiTrack(string(track.URI), artist, track.Name, track.TimeDuration().String())
			}

			folder.AddPlaylist(sconsify.InitPlaylist(artist.URI, " "+artist.Name+" Top Tracks", tracks))
		}

		infrastructure.Debugf("# of albums %v", len(simpleAlbumPage.Albums))
		for _, simpleAlbum := range simpleAlbumPage.Albums {
			infrastructure.Debugf("AlbumsID %v = %v", simpleAlbum.URI, simpleAlbum.Name)
			playlist := sconsify.InitOnDemandPlaylist(string(simpleAlbum.URI), " "+simpleAlbum.Name, true, func(playlist *sconsify.Playlist) {
				infrastructure.Debugf("Album id %v", playlist.ToSpotifyID())
				if simpleTrackPage, err := spotify.client.GetAlbumTracks(webspotify.ID(playlist.ToSpotifyID())); err == nil {
					infrastructure.Debugf("# of tracks %v", len(simpleTrackPage.Tracks))
					for _, track := range simpleTrackPage.Tracks {
						playlist.AddTrack(sconsify.InitWebApiTrack(string(track.URI), artist, track.Name, track.TimeDuration().String()))
					}
				}
			})
			folder.AddPlaylist(playlist)
		}

		spotify.events.ArtistAlbums(folder)
	}
}
Ejemplo n.º 2
0
func (spotify *Spotify) artistTopTrack(artist *sconsify.Artist) {
	if fullTracks, err := spotify.client.GetArtistsTopTracks(webspotify.ID(artist.GetSpotifyID()), "GB"); err == nil {
		tracks := make([]*sconsify.Track, len(fullTracks))
		for i, track := range fullTracks {
			tracks[i] = sconsify.InitWebApiTrack(string(track.URI), artist, track.Name, track.TimeDuration().String())
		}

		topTracksPlaylist := sconsify.InitPlaylist(artist.URI, artist.Name, tracks)
		spotify.events.ArtistTopTracks(topTracksPlaylist)
	}
}
Ejemplo n.º 3
0
func GetTrax(c *spotify.Client, id spotify.ID) ([]spotify.ID, error) {
	discTrax, err := c.GetPlaylistTracksOpt("spotifydiscover", id, nil, "items(track(id, name))")
	if err != nil {
		return nil, errors.New("getplay err: " + err.Error())
	}

	ids := make([]spotify.ID, 0, len(discTrax.Tracks))
	for _, t := range discTrax.Tracks {
		fmt.Printf("ID: %v, Name: %v\n", t.Track.ID, t.Track.Name)
		ids = append(ids, spotify.ID(t.Track.ID))
	}

	return ids, nil
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: brandur/wgt2
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())
	}
}