mirror of
https://github.com/koel/koel
synced 2025-03-02 22:27:13 +00:00
Koel can now integrate and use the rich information from Last.fm. Now whenever a song is played, its album and artist information will be queried from Last.fm and cached for later use. What's better, if an album has no cover, Koel will try to update its cover if one is found on Last.fm. In order to use this feature, users only need to provide valid Last.fm API credentials (namely LASTFM_API_KEY and LASTFM_API_SECRET) in .env. A npm and gulp rebuild is also required - just like with every update.
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Models\Artist;
|
|
use App\Models\Interaction;
|
|
use App\Models\Playlist;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
|
|
class DataController extends Controller
|
|
{
|
|
/**
|
|
* Get a set of application data.
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function index()
|
|
{
|
|
$playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
|
|
|
|
// We don't need full song data, just ID's
|
|
foreach ($playlists as &$playlist) {
|
|
$playlist['songs'] = array_pluck($playlist['songs'], 'id');
|
|
}
|
|
|
|
return response()->json([
|
|
'artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(),
|
|
'settings' => Setting::all()->lists('value', 'key'),
|
|
'playlists' => $playlists,
|
|
'interactions' => Interaction::byCurrentUser()->get(),
|
|
'users' => auth()->user()->is_admin ? User::all() : [],
|
|
'user' => auth()->user(),
|
|
'useLastfm' => env('LASTFM_API_KEY') && env('LASTFM_SECRET'),
|
|
]);
|
|
}
|
|
}
|