koel/app/Http/Controllers/API/SongController.php

61 lines
1.4 KiB
PHP
Raw Normal View History

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
}
}
/**
* 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(),
]);
}
2015-12-13 04:42:28 +00:00
}