Lastify
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
Lastify is a PHP library that syncs your music between Last.fm, Spotify, etc., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require hansott/lastify, (*4)
## Usage
1. Generate a spotify access token: [Spotify Api Console](https://developer.spotify.com/web-api/console/get-current-user/) (OAuth Scope: playlist-read-private, playlist-modify-public & playlist-modify-private)
2. Create a last.fm API account and copy the api key: [Create API account](http://www.last.fm/api/account/create) (Note: You cannot view your API account after creating.)
``` php
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
require_once __DIR__.'/../vendor/autoload.php';
use HansOtt\Lastify\TrackInfo;
use HansOtt\Lastify\Synchronizer;
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());
~/Code/lastify master $ php examples/syncTopTracks.php
[1/20] Syncing This Is the Life - Amy Macdonald
[2/20] Syncing Banquet - Bloc Party
[3/20] Syncing The Passenger - Iggy Pop
[4/20] Syncing A Forest - The Cure
[5/20] Syncing Not Alone - Time
[6/20] Syncing Somebody Told Me - The Killers
[7/20] Syncing This Modern Love - Bloc Party
[8/20] Syncing Ex's & Oh's - Elle King
[9/20] Syncing Octopus - Bloc Party
[10/20] Syncing Ratchet - Bloc Party
[11/20] Syncing Comptine d'un autre été, l'aprÚs-midi - Yann Tiersen
[12/20] Syncing Soft Spoken Words - Trixie Whitley
[13/20] Syncing Back to Black - Amy Winehouse
[14/20] Syncing Pocket Piano - DJ Mehdi
[15/20] Syncing Lucky Boy - DJ Mehdi
[16/20] Syncing Starblazer - Deetron
[17/20] Syncing Wappy Flirt - Original Mix - Hi-Lo
[18/20] Syncing Signatune (Thomas Bangalter edit) - DJ Mehdi
[19/20] Syncing Slowly - Festival Mix - Dropout
[20/20] Syncing The Aviating - Alec Troniq
Change log
Please see CHANGELOG for more information what has changed recently., (*5)
Testing
bash
$ composer test, (*6)
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*7)
Security
If you discover any security related issues, please email hansott at hotmail be instead of using the issue tracker., (*8)
Credits
License
The MIT License (MIT). Please see License File for more information., (*9)