From 1eb554e59bc2ae7a813af03d884bda54efbcbef5 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Thu, 6 Jun 2024 15:05:52 +0000 Subject: Playlist: add m3u files --- laravel/app/Http/Controllers/PlaylistController.php | 5 +++++ laravel/app/Playlist.php | 10 ++++++++++ laravel/resources/views/playlist.blade.php | 1 + laravel/routes/web.php | 1 + 4 files changed, 17 insertions(+) (limited to 'laravel') diff --git a/laravel/app/Http/Controllers/PlaylistController.php b/laravel/app/Http/Controllers/PlaylistController.php index c055601..96b2dad 100644 --- a/laravel/app/Http/Controllers/PlaylistController.php +++ b/laravel/app/Http/Controllers/PlaylistController.php @@ -27,4 +27,9 @@ class PlaylistController extends Controller // Do people want to see the favorites playlist when they've added to it, or stay on the song? return redirect()->route('playlist.show', [ 'playlist' => $playlistName]); } + public function m3u($playlistName) + { + $pl = Playlist::where('name', $playlistName)->firstOrFail(); + return response($pl->m3u, 200)->header('Content-Type', 'audio/x-mpegurl'); + } } diff --git a/laravel/app/Playlist.php b/laravel/app/Playlist.php index 7284b0e..f56e1be 100644 --- a/laravel/app/Playlist.php +++ b/laravel/app/Playlist.php @@ -11,4 +11,14 @@ class Playlist extends Model { return $this->belongsToMany('App\Song'); } + public function getM3uAttribute() + { + $output = "#EXTM3U\n"; + foreach($this->songs as $song) { + if ($song->audio){ + $output .= config('app.url') . $song->audio . "\n"; + } + } + return $output; + } } diff --git a/laravel/resources/views/playlist.blade.php b/laravel/resources/views/playlist.blade.php index 23f192b..8817cd4 100644 --- a/laravel/resources/views/playlist.blade.php +++ b/laravel/resources/views/playlist.blade.php @@ -4,6 +4,7 @@ @section('content')

Playlist "{{$playlist->name}}"

+ Download audio playlist file