Support for exporting the watch history as playlist

This commit is contained in:
Bnyro 2023-01-27 17:27:40 +01:00
parent 604eb5edcc
commit 8a801ab404
2 changed files with 20 additions and 2 deletions

View file

@ -4,6 +4,8 @@
<div class="flex"> <div class="flex">
<div> <div>
<button class="btn" v-t="'actions.clear_history'" @click="clearHistory" /> <button class="btn" v-t="'actions.clear_history'" @click="clearHistory" />
<button class="btn mx-3" v-t="'actions.export_to_json'" @click="exportHistory" />
</div> </div>
<div class="right-1"> <div class="right-1">
@ -71,6 +73,22 @@ export default {
} }
this.videos = []; this.videos = [];
}, },
exportHistory() {
const dateStr = new Date().toISOString().split(".")[0];
let json = {
format: "Piped",
version: 1,
playlists: [
{
name: `Piped History ${dateStr}`,
type: "history",
visibility: "private",
videos: this.videos.map(video => "https://youtube.com" + video.url),
},
],
};
this.download(JSON.stringify(json), `piped_history_${dateStr}.json`, "application/json");
},
}, },
}; };
</script> </script>

View file

@ -241,8 +241,8 @@ const mixin = {
return localSubscriptions.join(","); return localSubscriptions.join(",");
}, },
/* generate a temporary file and ask the user to download it */ /* generate a temporary file and ask the user to download it */
download(text, filename, type) { download(text, filename, mimeType) {
var file = new Blob([text], { type: type }); var file = new Blob([text], { type: mimeType });
const elem = document.createElement("a"); const elem = document.createElement("a");