mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
add playlist export functionality
This commit is contained in:
parent
abdc80cdbe
commit
0a7c2d6c0c
1 changed files with 37 additions and 1 deletions
|
@ -3,7 +3,13 @@
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<button v-t="'actions.create_playlist'" class="btn" @click="createPlaylist" />
|
<div class="flex justify-between mb-3">
|
||||||
|
<button v-t="'actions.create_playlist'" class="btn" @click="createPlaylist" />
|
||||||
|
<div class="flex">
|
||||||
|
<button v-t="'actions.export_to_json'" class="btn" @click="exportPlaylists" />
|
||||||
|
<button v-t="'actions.import_from_json'" class="btn ml-2" @click="importPlaylists" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="video-grid">
|
<div class="video-grid">
|
||||||
<div v-for="playlist in playlists" :key="playlist.id">
|
<div v-for="playlist in playlists" :key="playlist.id">
|
||||||
|
@ -111,6 +117,36 @@ export default {
|
||||||
else this.fetchPlaylists();
|
else this.fetchPlaylists();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
exportPlaylists() {
|
||||||
|
if (!this.playlists) return;
|
||||||
|
let json = {
|
||||||
|
playlists: [],
|
||||||
|
};
|
||||||
|
let playlistsSize = this.playlists.length;
|
||||||
|
for (var i = 0; i < playlistsSize; i++) {
|
||||||
|
this.fetchPlaylistJson(this.playlists[i].id, playlist => {
|
||||||
|
json.playlists.push(playlist);
|
||||||
|
if (playlistsSize != json.playlists.length) return;
|
||||||
|
this.download(JSON.stringify(json), "playlists.json", "application/json");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async fetchPlaylistJson(playlistId, onSuccess) {
|
||||||
|
let playlist = await this.fetchJson(this.authApiUrl() + "/playlists/" + playlistId);
|
||||||
|
let playlistJson = {
|
||||||
|
name: playlist.name,
|
||||||
|
// possible other types: history, watch later, ...
|
||||||
|
type: "playlist",
|
||||||
|
// as Invidious supports public and private playlists
|
||||||
|
visibility: "private",
|
||||||
|
// list of the videos, starting with "https://youtube.com" to clarify that those are YT videos
|
||||||
|
videos: [],
|
||||||
|
};
|
||||||
|
for (var i = 0; i < playlist.relatedStreams.length; i++) {
|
||||||
|
playlistJson.videos.push("https://youtube.com" + playlist.relatedStreams[i].url);
|
||||||
|
}
|
||||||
|
onSuccess(playlistJson);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue