Search the Musixmatch API with cache support
, (*1)
The atomescrochus/laravel-musixmatch
package provide and easy way to search the Musixmatch API from any Laravel >= 5.3 application., (*2)
This package is NOT usable in production, and should still be considered a work in progress (_contribution welcomed!_). It requires PHP >= 7.0
., (*3)
Install
You can install this package via composer:, (*4)
``` bash
$ composer require atomescrochus/laravel-musixmatch, (*5)
Then you have to install the package' service provider, _unless you are running Laravel >=5.5_ (it'll use package auto-discovery) :
```php
// config/app.php
'providers' => [
...
Atomescrochus\Musixmatch\MusixmatchServiceProvider::class,
];
You will have to publish the configuration files also if you want to change the default value:, (*6)
php artisan vendor:publish --provider="Atomescrochus\Musixmatch\MusixmatchServiceProvider" --tag="config"
You are also required to put the values you can fetch in your Gracenote developer account in your .env files:, (*7)
MUSIXMATCH_APIKEY=12345678
Usage
``` php
// here is an example query to search Musixmatch API
$search = new \Atomescrochus\Musixmatch\Musixmatch();
$results = $search->trackSearch('poker face', 'lady gaga')->results();, (*8)
// or if you already have the track id and wants the lyrics
$lyrics = new \Atomescrochus\Musixmatch\Musixmatch();
$results = $lyrics->getLyrics(15476784)->results();, (*9)
// you can change the default cache duration (of one day) like so
$lyrics->setCacheDuration(60); // in minutes, (*10)
// If you ever find yourself that you want to check your local cache for a result, without actually polling the API:
$results = $lyrics->cacheOnly()->getLyrics(15476784)->results();, (*11)
// In case you only want to check if the query exists in the cache, without actually pulling the data:
$existInCache = $lyrics->inCache()->getLyrics(15476784)->results(); // returns boolean
```, (*12)
Results
In the example above, what is returned in $results
is an object containing: a collection of results; a count value for the results; raw response data; cache information, and the unformatted query sent to the API., (*13)
Tests
This is basically a wrapper around the API. We're assuming the Musixmatch API has been tested, and we won't make duplicated tests., (*14)
Change log
Please see CHANGELOG for more information on what has changed recently., (*15)
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*16)
Security
If you discover any security related issues, please email jp@atomescroch.us instead of using the issue tracker., (*17)
Credits
License
The MIT License (MIT). Please see License File for more information., (*18)