Giter Club home page Giter Club logo

lastfm's Introduction

Last.fm API client for PHP 7

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

API keys

You can create a last.fm API account at http://www.last.fm/api/account/create.

Installation

Via Composer

$ composer require barryvanveen/lastfm

Laravel installation

Add a LASTFM_API_KEY variable to your .env configuration. You could also publish the default configuration and alter it yourself:

php  artisan vendor:publish --provider="Barryvanveen\Lastfm\LastfmServiceProvider"

Update config/app.php by adding the LastfmServiceProvider:

'providers' => [
    ...
    Barryvanveen\Lastfm\LastfmServiceprovider::class,
];

If you are using Laravel 5.5 the service provider will be used automagically by Laravel's package discovery.

Tested against Laravel 5.* but probably works in most versions because it is so simple. Please create an issue if it doesn't work for you.

Usage

Basic example

use Barryvanveen\Lastfm\Lastfm;
use GuzzleHttp\Client;
 
$lastfm = new Lastfm(new Client(), 'YourApiKey');
    
$albums = $lastfm->userTopAlbums('AnyUsername')->get();

Laravel example

use Barryvanveen\Lastfm\Lastfm;
 
public function index(Lastfm $lastfm)
{
    $albums = $lastfm->userTopAlbums('AnyUsername')->get();
    
    return view('home', compact('albums'));
}

All available methods

// Get top albums for user
$albums = $lastfm->userTopAlbums('AnyUsername')->get();
 
// Get top artists for user
$artists = $lastfm->userTopArtists('AnyUsername')->get();
 
// Get recent tracks for user
$tracks = $lastfm->userRecentTracks('AnyUsername')->get();
 
// Get user info
$info = $lastfm->userInfo('AnyUsername')->get();
 
// Get track that user is now listening to, or FALSE
$trackOrFalse = $lastfm->nowListening('AnyUsername'); 
 
// Get the weekly top albums given a starting day 
$albums = $lastfm->userWeeklyTopAlbums('AnyUsername', new \DateTime('2017-01-01'));                      
 
// Get the weekly top artists given a starting day 
$artists = $lastfm->userWeeklyTopArtists('AnyUsername', new \DateTime('2017-01-01'));
 
// Get the weekly top tracks given a starting day 
$tracks = $lastfm->userWeeklyTopTracks('AnyUsername', new \DateTime('2017-01-01'));

Filtering results

// Define time period for results
$lastfm->userTopAlbums('AnyUsername')
       ->period(Barryvanveen\Lastfm\Constants::PERIOD_WEEK)
       ->get();
                  
// Limit number of results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->get();     
                 
// Retrieve paginated results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->page(2)
       ->get();     

Valid time periods

// use these constants as an argument to ->period()
Barryvanveen\Lastfm\Constants::PERIOD_WEEK     = '7day';
Barryvanveen\Lastfm\Constants::PERIOD_MONTH    = '1month';
Barryvanveen\Lastfm\Constants::PERIOD_3_MONTHS = '3month';
Barryvanveen\Lastfm\Constants::PERIOD_6_MONTHS = '6month';
Barryvanveen\Lastfm\Constants::PERIOD_YEAR     = '12month';
Barryvanveen\Lastfm\Constants::PERIOD_OVERALL  = 'overall';

Official API docs

Read the official API documentation at http://www.last.fm/api.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

Copy phpunit.xml.dist to phpunit.xml and fill in your own LASTFM_API_KEY. Then run the tests using:

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

lastfm's People

Contributors

barryvanveen avatar bruno7kp 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.