2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Streamers\PHPStreamer;
|
2015-12-16 15:42:11 +00:00
|
|
|
use App\Http\Streamers\XAccelRedirectStreamer;
|
2015-12-16 16:15:20 +00:00
|
|
|
use App\Http\Streamers\XSendFileStreamer;
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Models\Song;
|
|
|
|
|
|
|
|
class SongController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Play a song.
|
2015-12-16 17:25:25 +00:00
|
|
|
*
|
2015-12-16 17:24:33 +00:00
|
|
|
* @link https://github.com/phanan/koel/wiki#streaming-music
|
2015-12-13 04:42:28 +00:00
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function play($id)
|
|
|
|
{
|
2015-12-16 15:42:11 +00:00
|
|
|
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();
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-20 12:17:35 +00:00
|
|
|
* Get extra information about a song via Last.fm.
|
2015-12-19 16:36:44 +00:00
|
|
|
*
|
2015-12-20 12:17:35 +00:00
|
|
|
* @param string $id
|
2015-12-19 16:36:44 +00:00
|
|
|
*
|
|
|
|
* @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(),
|
|
|
|
]);
|
|
|
|
}
|
2015-12-20 12:17:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrobble a song.
|
|
|
|
*
|
|
|
|
* @param string $id The song's ID
|
|
|
|
* @param string $timestamp The UNIX timestamp when the song started playing.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function scrobble($id, $timestamp)
|
|
|
|
{
|
|
|
|
return response()->json(Song::with('album.artist')->findOrFail($id)->scrobble($timestamp));
|
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|