Playlist Maker for Spotify

Learn how Spotify Web API (SWA) and Google Apps Script (GAS) turned the library into a flexible playlist builder with free scheduled execution.





By playlist constructor, we mean a mechanism for collecting, filtering, sorting and adding tracks.





Links to source code and documentation at the end of the article.





Problem

Having an official API has spawned many interesting tools for Spotify. In our context, consider Smarter Playlists . The graphical interface in the form of graphs, a lot of control blocks make it quite friendly for the average user.





Heavy use of the service revealed a number of disadvantages:





  • lack of listening history





  • limited addition of tracks





  • limited number of scheduled starts





  • incorrect work with Cyrillic





Over time, the desire for new sources of tracks is added here; more complex filtering algorithms. The service has stopped developing in terms of new features.

In this connection, there was a desire for an alternative that eliminates these disadvantages.





Decision

GAS JavaScript - Goofy. () .





GAS , . , 6 ; API 20 . , . Smarter Playlists, . .





, Goofy









  • , ,

















  • Last.fm , ,





. . Goofy . , .





  • SWA 50 . 51- 1-.





  • GAS Google Drive. SWA . , . , .





  • . 30 . . "" SWA.





  • - Last.fm. . , . , Spotify Google Drive. Last.fm Spotify.





( GAS) ( , ). .





1) : , .





Next, we create a trigger using graphical means of GAS. As a result, for example, once a minute the playlist will be updated with five random tracks.





function createHelloPlaylist() {
    let tracks = Source.getSavedTracks();
    Selector.keepRandom(tracks, 5);
    Playlist.saveWithReplace({
        name: 'Hello, playlist',
        tracks: tracks,
    });
}
      
      



2) Reveal your favorite tracks that have not been listened to for more than a month.





function templateSavedAndForgot(){
    let recentTracks = Source.getRecentTracks(2500);
    let savedTracks = Source.getSavedTracks(); 
    Filter.removeTracks(savedTracks, recentTracks);

    let startDate = new Date('2006-01-01');
    let endDate = Filter.getDateRel(30, 'endDay');
    Filter.rangeDateAbs(savedTracks, startDate, endDate);

    Selector.keepRandom(savedTracks, 20);    
    Order.sort(savedTracks, 'meta.added_at', 'asc');
    Playlist.saveWithReplace({
        name: '  ',
        tracks: savedTracks,
        randomCover: 'update', //    
    });
}
      
      



3) Get tracks of albums and singles of tracked artists per week.





function createNewRelease() {
    const playlistId = 'abc';
    let tracks = Source.getArtistsTracks({
        artist: { 
          followed_include: true 
        },
        album: { 
          groups: 'album,single', 
          release_date: { sinceDays: 7, beforeDays: 0 } 
        },
    });
    Order.shuffle(tracks);

    Combiner.push(tracks, Source.getPlaylistTracks('name', playlistId));
    Filter.removeTracks(tracks, RecentTracks.get(3000));
    Filter.matchOriginalOnly(tracks);
    
    Playlist.saveWithReplace({
        id: playlistId,
        name: ' ',
        tracks: tracks,
        randomCover: 'update',
    });
}
      
      



Links

The documentation was written with a focus on the user who is not familiar with programming. To make it possible to use Goofy through copy-paste templates and examples.





Source code on GitHub including forum .








All Articles