diff --git a/app/Http/Controllers/TracksController.php b/app/Http/Controllers/TracksController.php index 8c744383..e55f447c 100644 --- a/app/Http/Controllers/TracksController.php +++ b/app/Http/Controllers/TracksController.php @@ -20,6 +20,7 @@ namespace Poniverse\Ponyfm\Http\Controllers; +use Illuminate\Http\Request; use Poniverse\Ponyfm\Models\ResourceLogItem; use Poniverse\Ponyfm\Models\Track; use Poniverse\Ponyfm\Models\TrackFile; @@ -77,6 +78,41 @@ class TracksController extends Controller return View::make('tracks.embed', ['track' => $track, 'user' => $userData]); } + public function getOembed(Request $request) + { + if (!$request->has('url')) { + App::abort(404); + } + + $parsedUrl = parse_url($request->input('url')); + $id = preg_match('(\d+)', $parsedUrl['path']); + + $track = Track + ::whereId($id) + ->published() + ->userDetails() + ->first(); + + if (!$track || !$track->canView(Auth::user())) { + App::abort(404); + } + + $output = [ + 'version' => '1.0', + 'type' => 'rich', + 'provider_name' => 'Pony.fm', + 'provider_url' => 'https://pony.fm', + 'width' => 480, + 'height' => 130, + 'title' => $track->title, + 'author_name' => $track->user->display_name, + 'author_url' => $track->user->url, + 'html' => '' + ]; + + return Response::json($output); + } + public function getTrack($id, $slug) { $track = Track::find($id); diff --git a/resources/views/tracks/show.blade.php b/resources/views/tracks/show.blade.php index f61c449f..4d84fe4b 100644 --- a/resources/views/tracks/show.blade.php +++ b/resources/views/tracks/show.blade.php @@ -46,6 +46,8 @@ + + @endsection @section('app_content') diff --git a/routes/web.php b/routes/web.php index 6cda69af..f4dcb7fb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -77,7 +77,7 @@ Route::get('p{id}/dl.{extension}', 'PlaylistsController@getDownload'); Route::get('notifications', 'AccountController@getNotifications'); - +Route::get('oembed', 'TracksController@getOembed'); Route::group(['prefix' => 'api/v1', 'middleware' => 'json-exceptions'], function () { Route::get('/tracks/radio-details/{hash}', 'Api\V1\TracksController@getTrackRadioDetails');