Giter Site home page Giter Site logo

lastify's Introduction

Lastify

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Lastify is a PHP library that syncs your music between Last.fm, Spotify, etc.

Install

Via Composer

$ composer require hansott/lastify

Usage

  1. Generate a spotify access token: Spotify Api Console (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 (Note: You cannot view your API account after creating.)
<?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.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email hansott at hotmail be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

lastify's People

Contributors

hansott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.