download playlists as txt

This commit is contained in:
Bnyro 2022-08-02 10:08:26 +02:00
parent e0cf9e6182
commit fa88624f8b
3 changed files with 30 additions and 1 deletions

View File

@ -18,6 +18,9 @@
<button class="btn mr-1" v-if="authenticated && !isPipedPlaylist" @click="clonePlaylist"> <button class="btn mr-1" v-if="authenticated && !isPipedPlaylist" @click="clonePlaylist">
{{ $t("actions.clone_playlist") }}<font-awesome-icon class="ml-3" icon="clone" /> {{ $t("actions.clone_playlist") }}<font-awesome-icon class="ml-3" icon="clone" />
</button> </button>
<button class="btn mr-1" @click="downloadPlaylistAsTxt">
{{ $t("actions.download_as_txt") }}
</button>
<a class="btn" :href="getRssUrl"> <a class="btn" :href="getRssUrl">
<font-awesome-icon icon="rss" /> <font-awesome-icon icon="rss" />
</a> </a>
@ -133,6 +136,22 @@ export default {
} else alert(resp.error); } 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);
},
}, },
}; };
</script> </script>

View File

@ -88,7 +88,8 @@
"different_auth_instance": "Use a different instance for authentication", "different_auth_instance": "Use a different instance for authentication",
"instance_auth_selection": "Autentication Instance Selection", "instance_auth_selection": "Autentication Instance Selection",
"clone_playlist": "Clone Playlist", "clone_playlist": "Clone Playlist",
"clone_playlist_success": "Successfully cloned!" "clone_playlist_success": "Successfully cloned!",
"download_as_txt": "Download as .txt"
}, },
"comment": { "comment": {
"pinned_by": "Pinned by", "pinned_by": "Pinned by",

View File

@ -220,6 +220,15 @@ const mixin = {
const localSubscriptions = this.getLocalSubscriptions(); const localSubscriptions = this.getLocalSubscriptions();
return localSubscriptions.join(","); 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: { computed: {
theme() { theme() {