about summary refs log tree commit diff
path: root/laravel/app
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 /laravel/app
parentcde3d35dff39e9fd4ef75a748b1c79ffd785e226 (diff)
downloadprosongsa-1eb554e59bc2ae7a813af03d884bda54efbcbef5.tar.gz
Playlist: add m3u files
Diffstat (limited to 'laravel/app')
-rw-r--r--laravel/app/Http/Controllers/PlaylistController.php5
-rw-r--r--laravel/app/Playlist.php10
2 files changed, 15 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;
+    }
 }