about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2024-06-06 15:05:52 +0000
committerZach DeCook <zachdecook@librem.one>2024-06-06 15:13:26 +0000
commit1eb554e59bc2ae7a813af03d884bda54efbcbef5 (patch)
treeac79e811b0a2b62333f7c854c1562d063a69a829
parentcde3d35dff39e9fd4ef75a748b1c79ffd785e226 (diff)
downloadprosongsa-1eb554e59bc2ae7a813af03d884bda54efbcbef5.tar.gz
Playlist: add m3u files
-rw-r--r--laravel/app/Http/Controllers/PlaylistController.php5
-rw-r--r--laravel/app/Playlist.php10
-rw-r--r--laravel/resources/views/playlist.blade.php1
-rw-r--r--laravel/routes/web.php1
4 files changed, 17 insertions, 0 deletions
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')
 
     <h2>Playlist "<i>{{$playlist->name}}</i>"</h2>
+    <a href="/playlist/{{$playlist->name}}.m3u">Download audio playlist file</a>
     <ul>
     @foreach($playlist->songs as $song)
         <li><a href='{{ route('song.show', ['song' => $song, 'playlist' => $playlist]) }}'>{{$song->name}}</a>
diff --git a/laravel/routes/web.php b/laravel/routes/web.php
index c783313..3618216 100644
--- a/laravel/routes/web.php
+++ b/laravel/routes/web.php
@@ -15,6 +15,7 @@ Route::get('/', function () {
     return view('welcome');
 })->name('song.list');
 Route::post('/new/song', 'SongController@post')->name('song.postnew')/*->middleware('can:create,App\Song')*/;
+Route::get('/playlist/{playlist}.m3u', 'PlaylistController@m3u')->name('playlist.m3u');
 Route::get('/playlist/{playlist}', 'PlaylistController@show')->name('playlist.show');
 Route::post('/playlist/{playlist}/{song}', 'PlaylistController@post')->name('playlist.post');
 Route::get('/s/{song}', 'SongController@show')->name('song.show');