koel/app/Http/Controllers/API/iTunesController.php
2018-08-29 13:15:23 +07:00

31 lines
777 B
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Requests\API\ViewSongOnITunesRequest;
use App\Models\Album;
use App\Services\iTunesService;
use Illuminate\Http\RedirectResponse;
class iTunesController extends Controller
{
private $iTunesService;
public function __construct(iTunesService $iTunesService)
{
$this->iTunesService = $iTunesService;
}
/**
* View a song on iTunes store.
*
* @return RedirectResponse
*/
public function viewSong(ViewSongOnITunesRequest $request, Album $album)
{
$url = $this->iTunesService->getTrackUrl($request->q, $album->name, $album->artist->name);
abort_unless($url, 404, "Koel can't find such a song on iTunes Store.");
return redirect($url);
}
}