From fa88624f8b858d1f95e3d7ead04e7a7da4b32518 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 2 Aug 2022 10:08:26 +0200 Subject: [PATCH] download playlists as txt --- src/components/PlaylistPage.vue | 19 +++++++++++++++++++ src/locales/en.json | 3 ++- src/main.js | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index 67e5e9a7..550f29b6 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -18,6 +18,9 @@ + @@ -133,6 +136,22 @@ export default { } else alert(resp.error); }); }, + downloadPlaylistAsTxt() { + var data = ""; + this.playlist.relatedStreams.forEach(element => { + data += "https://piped.kavin.rocks" + element.url + "\n"; + }); + this.download(data, this.playlist.name + ".txt"); + }, + download(text, filename) { + var element = document.createElement("a"); + element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text)); + element.setAttribute("download", filename); + element.style.display = "none"; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }, }, }; diff --git a/src/locales/en.json b/src/locales/en.json index 64f403b3..229cacb5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -88,7 +88,8 @@ "different_auth_instance": "Use a different instance for authentication", "instance_auth_selection": "Autentication Instance Selection", "clone_playlist": "Clone Playlist", - "clone_playlist_success": "Successfully cloned!" + "clone_playlist_success": "Successfully cloned!", + "download_as_txt": "Download as .txt" }, "comment": { "pinned_by": "Pinned by", diff --git a/src/main.js b/src/main.js index 171e6a33..0225cb79 100644 --- a/src/main.js +++ b/src/main.js @@ -220,6 +220,15 @@ const mixin = { const localSubscriptions = this.getLocalSubscriptions(); return localSubscriptions.join(","); }, + download(text, filename) { + var element = document.createElement("a"); + element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text)); + element.setAttribute("download", filename); + element.style.display = "none"; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }, }, computed: { theme() {