mirror of
https://github.com/koel/koel
synced 2024-12-13 14:12:27 +00:00
cf27ed713d
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.
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Streamers\PHPStreamer;
|
|
use App\Http\Streamers\XAccelRedirectStreamer;
|
|
use App\Http\Streamers\XSendFileStreamer;
|
|
use App\Models\Song;
|
|
|
|
class SongController extends Controller
|
|
{
|
|
/**
|
|
* Play a song.
|
|
*
|
|
* @link https://github.com/phanan/koel/wiki#streaming-music
|
|
*
|
|
* @param $id
|
|
*/
|
|
public function play($id)
|
|
{
|
|
switch (env('STREAMING_METHOD')) {
|
|
case 'x-sendfile':
|
|
return (new XSendFileStreamer($id))->stream();
|
|
case 'x-accel-redirect':
|
|
return (new XAccelRedirectStreamer($id))->stream();
|
|
default:
|
|
return (new PHPStreamer($id))->stream();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the lyrics of a song.
|
|
*
|
|
* @param $id
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getLyrics($id)
|
|
{
|
|
return response()->json(Song::findOrFail($id)->lyrics);
|
|
}
|
|
|
|
/**
|
|
* Get extra information about a song via Last.fm
|
|
*
|
|
* @param string $id
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function getInfo($id)
|
|
{
|
|
$song = Song::with('album.artist')->findOrFail($id);
|
|
|
|
return response()->json([
|
|
'lyrics' => $song->lyrics,
|
|
'album_info' => $song->album->getInfo(),
|
|
'artist_info' => $song->album->artist->getInfo(),
|
|
]);
|
|
}
|
|
}
|