2016-12-11 13:08:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2017-12-09 18:34:27 +00:00
|
|
|
use App\Http\Requests\API\ViewSongOnITunesRequest;
|
2016-12-11 13:08:30 +00:00
|
|
|
use App\Models\Album;
|
2018-08-19 14:40:25 +00:00
|
|
|
use App\Services\iTunesService;
|
2017-06-04 01:30:45 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2016-12-11 13:08:30 +00:00
|
|
|
|
|
|
|
class iTunesController extends Controller
|
|
|
|
{
|
2018-08-19 14:40:25 +00:00
|
|
|
private $iTunesService;
|
|
|
|
|
|
|
|
public function __construct(iTunesService $iTunesService)
|
|
|
|
{
|
|
|
|
$this->iTunesService = $iTunesService;
|
|
|
|
}
|
|
|
|
|
2016-12-11 13:08:30 +00:00
|
|
|
/**
|
|
|
|
* View a song on iTunes store.
|
|
|
|
*
|
2017-12-09 18:34:27 +00:00
|
|
|
* @param ViewSongOnITunesRequest $request
|
|
|
|
* @param Album $album
|
2016-12-11 13:08:30 +00:00
|
|
|
*
|
2017-06-04 01:30:45 +00:00
|
|
|
* @return RedirectResponse
|
2016-12-11 13:08:30 +00:00
|
|
|
*/
|
2017-12-09 18:34:27 +00:00
|
|
|
public function viewSong(ViewSongOnITunesRequest $request, Album $album)
|
2016-12-11 13:08:30 +00:00
|
|
|
{
|
2018-08-19 14:40:25 +00:00
|
|
|
$url = $this->iTunesService->getTrackUrl($request->q, $album->name, $album->artist->name);
|
2017-04-29 02:55:41 +00:00
|
|
|
abort_unless($url, 404, "Koel can't find such a song on iTunes Store.");
|
|
|
|
|
|
|
|
return redirect($url);
|
2016-12-11 13:08:30 +00:00
|
|
|
}
|
|
|
|
}
|