1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\API; |
4
|
|
|
|
5
|
|
|
use App\Http\Requests\API\SongUpdateRequest; |
6
|
|
|
use App\Models\Song; |
7
|
|
|
use App\Services\Streamers\PHPStreamer; |
8
|
|
|
use App\Services\Streamers\S3Streamer; |
9
|
|
|
use App\Services\Streamers\TranscodingStreamer; |
10
|
|
|
use App\Services\Streamers\XAccelRedirectStreamer; |
11
|
|
|
use App\Services\Streamers\XSendFileStreamer; |
12
|
|
|
use Illuminate\Http\JsonResponse; |
13
|
|
|
use Illuminate\Http\RedirectResponse; |
14
|
|
|
use Illuminate\Http\Request; |
15
|
|
|
use Illuminate\Routing\Redirector; |
16
|
|
|
use App\Services\Streamers\GCPStreamer; |
17
|
|
|
|
18
|
|
|
class SongController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Play/stream a song. |
22
|
|
|
* |
23
|
|
|
* @link https://github.com/phanan/koel/wiki#streaming-music |
24
|
|
|
* |
25
|
|
|
* @param Request $request |
26
|
|
|
* @param Song $song The song to stream. |
27
|
|
|
* @param null|bool $transcode Whether to force transcoding the song. |
28
|
|
|
* If this is omitted, by default Koel will transcode FLAC. |
29
|
|
|
* @param null|int $bitRate The target bit rate to transcode, defaults to OUTPUT_BIT_RATE. |
30
|
|
|
* Only taken into account if $transcode is truthy. |
31
|
|
|
* |
32
|
|
|
* @return RedirectResponse|Redirector |
33
|
|
|
*/ |
34
|
|
|
public function play(Request $request, Song $song, $transcode = null, $bitRate = null) |
35
|
|
|
{ |
36
|
|
|
if ($song->s3_params) { |
37
|
|
|
return (new S3Streamer($song))->stream(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($song->gcp_params) { |
|
|
|
|
41
|
|
|
return (new GCPStreamer($song))->stream(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// If `transcode` parameter isn't passed, the default is to only transcode FLAC. |
45
|
|
|
if ($transcode === null && ends_with(mime_content_type($song->path), 'flac')) { |
46
|
|
|
$transcode = true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$streamer = null; |
|
|
|
|
50
|
|
|
|
51
|
|
|
if ($transcode) { |
52
|
|
|
$streamer = new TranscodingStreamer( |
53
|
|
|
$song, |
54
|
|
|
$bitRate ?: config('koel.streaming.bitrate'), |
55
|
|
|
floatval($request->time) |
56
|
|
|
); |
57
|
|
|
} else { |
58
|
|
|
switch (config('koel.streaming.method')) { |
59
|
|
|
case 'x-sendfile': |
60
|
|
|
$streamer = new XSendFileStreamer($song); |
61
|
|
|
break; |
62
|
|
|
case 'x-accel-redirect': |
63
|
|
|
$streamer = new XAccelRedirectStreamer($song); |
64
|
|
|
break; |
65
|
|
|
default: |
66
|
|
|
$streamer = new PHPStreamer($song); |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$streamer->stream(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get extra information about a song via Last.fm. |
76
|
|
|
* |
77
|
|
|
* @param Song $song |
78
|
|
|
* |
79
|
|
|
* @return JsonResponse |
80
|
|
|
*/ |
81
|
|
|
public function show(Song $song) |
82
|
|
|
{ |
83
|
|
|
return response()->json([ |
84
|
|
|
'lyrics' => $song->lyrics, |
85
|
|
|
'album_info' => $song->album->getInfo(), |
86
|
|
|
'artist_info' => $song->artist->getInfo(), |
87
|
|
|
'youtube' => $song->getRelatedYouTubeVideos(), |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Update songs info. |
93
|
|
|
* |
94
|
|
|
* @param SongUpdateRequest $request |
95
|
|
|
* |
96
|
|
|
* @return JsonResponse |
97
|
|
|
*/ |
98
|
|
|
public function update(SongUpdateRequest $request) |
99
|
|
|
{ |
100
|
|
|
return response()->json(Song::updateInfo($request->songs, $request->data)); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.