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

28 lines
659 B
PHP
Raw Normal View History

2016-12-11 13:08:30 +00:00
<?php
namespace App\Http\Controllers\API;
use App\Http\Requests\API\ViewSongRequest;
use App\Models\Album;
2017-06-04 01:30:45 +00:00
use Illuminate\Http\RedirectResponse;
2016-12-11 13:08:30 +00:00
use iTunes;
class iTunesController extends Controller
{
/**
* View a song on iTunes store.
*
* @param ViewSongRequest $request
* @param Album $album
*
2017-06-04 01:30:45 +00:00
* @return RedirectResponse
2016-12-11 13:08:30 +00:00
*/
public function viewSong(ViewSongRequest $request, Album $album)
{
$url = iTunes::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
}
}