PHP code example of hansott / lastify

1. Go to this page and download the library: Download hansott/lastify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hansott / lastify example snippets

 php


error_reporting(-1);
ini_set('display_errors', 'On');


use HansOtt\Lastify\Services\LastFm;
use HansOtt\Lastify\Services\Spotify;
use HansOtt\Lastify\SyncProgressCallback;

$lastFm = LastFm::connect('your-lastfm-api-key');
$spotify = Spotify::connect('your-spotify-access-token');

$synchronizer = new Synchronizer($spotify);
$topTracks = $lastFm->getTopTracks('your-lastfm-username', 20);
$lovedTracks = $lastFm->getLovedTracks('your-lastfm-username', 20);

class ProgressCallback implements SyncProgressCallback {
    public function onProgress($current, $total, TrackInfo $currentItem)
    {
        echo sprintf("[%s/%s] Syncing %s \n", $current, $total, $currentItem->toString());
    }
}

$synchronizer->syncToPlaylist('Top Tracks', $topTracks, new ProgressCallback());
$synchronizer->syncToPlaylist('Loved Tracks', $lovedTracks, new ProgressCallback());