From 08329fc8bc74072417cf2a753803f1ca1ad7fe0e Mon Sep 17 00:00:00 2001 From: Robert Sprunk Date: Mon, 1 Feb 2021 20:28:11 +0100 Subject: [PATCH 1/2] Export playlists to m3u using web interface --- supysonic/frontend/playlist.py | 23 ++++++++++++++++++++++- supysonic/templates/playlist_export.m3u | 12 ++++++++++++ supysonic/templates/playlists.html | 4 +++- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 supysonic/templates/playlist_export.m3u diff --git a/supysonic/frontend/playlist.py b/supysonic/frontend/playlist.py index ff6920b..a0cbeb4 100644 --- a/supysonic/frontend/playlist.py +++ b/supysonic/frontend/playlist.py @@ -7,7 +7,7 @@ import uuid -from flask import flash, redirect, render_template, request, url_for +from flask import Response, flash, redirect, render_template, request, url_for from pony.orm import ObjectNotFound from ..db import Playlist @@ -40,6 +40,27 @@ def playlist_details(uid): return render_template("playlist.html", playlist=playlist) +@frontend.route("/playlist//export") +def playlist_export(uid): + try: + uid = uuid.UUID(uid) + except ValueError: + flash("Invalid playlist id") + return redirect(url_for("frontend.playlist_index")) + + try: + playlist = Playlist[uid] + except ObjectNotFound: + flash("Unknown playlist") + return redirect(url_for("frontend.playlist_index")) + + return Response( + render_template("playlist_export.m3u", playlist=playlist), + mimetype="audio/mpegurl", + headers={"Content-disposition": f"attachment; filename={playlist.name}.m3u"} + ) + + @frontend.route("/playlist/", methods=["POST"]) def playlist_update(uid): diff --git a/supysonic/templates/playlist_export.m3u b/supysonic/templates/playlist_export.m3u new file mode 100644 index 0000000..c56d9ef --- /dev/null +++ b/supysonic/templates/playlist_export.m3u @@ -0,0 +1,12 @@ +{#- + This file is part of Supysonic. + Supysonic is a Python implementation of the Subsonic server API. + + Copyright (C) 2013-2018 Alban 'spl0k' Féron + 2017 Óscar García Amor + + Distributed under terms of the GNU AGPLv3 license. +-#} +{% for t in playlist.get_tracks() %} +{{ t.path }} +{% endfor %} \ No newline at end of file diff --git a/supysonic/templates/playlists.html b/supysonic/templates/playlists.html index 2388e99..4949f15 100644 --- a/supysonic/templates/playlists.html +++ b/supysonic/templates/playlists.html @@ -21,7 +21,7 @@ {% else %} - + {% for p in mine %} @@ -32,6 +32,8 @@ aria-label="Public playlist">{% else %}{% endif %} + From 9324025c41ca482e59253de2e90a3f3d6b1fcd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sat, 10 Apr 2021 15:47:31 +0200 Subject: [PATCH 2/2] Added disclaimer before exporting playlist --- supysonic/frontend/playlist.py | 8 +++++--- supysonic/static/js/supysonic.js | 2 +- supysonic/templates/playlists.html | 24 ++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/supysonic/frontend/playlist.py b/supysonic/frontend/playlist.py index a0cbeb4..4cd0418 100644 --- a/supysonic/frontend/playlist.py +++ b/supysonic/frontend/playlist.py @@ -40,6 +40,7 @@ def playlist_details(uid): return render_template("playlist.html", playlist=playlist) + @frontend.route("/playlist//export") def playlist_export(uid): try: @@ -57,9 +58,10 @@ def playlist_export(uid): return Response( render_template("playlist_export.m3u", playlist=playlist), mimetype="audio/mpegurl", - headers={"Content-disposition": f"attachment; filename={playlist.name}.m3u"} - ) - + headers={ + "Content-disposition": "attachment; filename={}.m3u".format(playlist.name) + }, + ) @frontend.route("/playlist/", methods=["POST"]) diff --git a/supysonic/static/js/supysonic.js b/supysonic/static/js/supysonic.js index e207c69..44c58b0 100644 --- a/supysonic/static/js/supysonic.js +++ b/supysonic/static/js/supysonic.js @@ -12,6 +12,6 @@ $(function () { $('[data-toggle="tooltip"]').tooltip() }); -$('#confirm-delete').on('show.bs.modal', function(e) { +$('.modal').on('show.bs.modal', function(e) { $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href')); }); diff --git a/supysonic/templates/playlists.html b/supysonic/templates/playlists.html index 4949f15..8e5c479 100644 --- a/supysonic/templates/playlists.html +++ b/supysonic/templates/playlists.html @@ -32,8 +32,8 @@ aria-label="Public playlist">{% else %}{% endif %} - + @@ -77,4 +77,24 @@ + {% endblock %}
PlaylistTracksPublic
PlaylistTracksPublicExportDelete
+
-