From 58cd6f8f37816da0ebfff2c4d4c6733f4c4914c5 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 1 Jan 2023 19:57:00 +0100 Subject: [PATCH 1/2] Add import from YouTube CSV --- public/efy | 1 + src/components/PlaylistsPage.vue | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 160000 public/efy diff --git a/public/efy b/public/efy new file mode 160000 index 00000000..51f030d7 --- /dev/null +++ b/public/efy @@ -0,0 +1 @@ +Subproject commit 51f030d755a9115f06341ecd78fbbf75ec600059 diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 02353d73..a6cdb5a4 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -160,21 +160,37 @@ export default { async importPlaylists() { const file = this.$refs.fileSelector.files[0]; let text = await file.text(); - let playlists = JSON.parse(text).playlists; - if (!playlists.length) { + let tasks = []; + // list of playlists exported from Piped + if (text.includes("playlists")) { + let playlists = JSON.parse(text).playlists; + if (!playlists.length) { + alert(this.$t("actions.no_valid_playlists")); + return; + } + for (var i = 0; i < playlists.length; i++) { + tasks.push(this.createPlaylistWithVideos(playlists[i])); + } + // CSV from Google Takeout + } else if (file.name.slice(-4).toLowerCase() == ".csv") { + const lines = text.split("\n"); + const playlist = { + name: lines[1].split(",")[4], + videos: lines + .slice(4, lines.length) + .filter(line => line != "") + .map(line => `https://youtube.com/watch?v=${line.split(",")[0]}`), + }; + tasks.push(this.createPlaylistWithVideos(playlist)); + } else { alert(this.$t("actions.no_valid_playlists")); return; } - let tasks = []; - for (var i = 0; i < playlists.length; i++) { - tasks.push(this.createPlaylistWithVideos(playlists[i])); - } await Promise.all(tasks); window.location.reload(); }, async createPlaylistWithVideos(playlist) { let newPlaylist = await this.createPlaylist(playlist.name); - console.log(newPlaylist); let videoIds = playlist.videos.map(url => url.substr(-11)); await this.addVideosToPlaylist(newPlaylist.playlistId, videoIds); }, From 5dbc82168a15f4d9f1ebb421f68595ba5fcc0486 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 1 Jan 2023 20:00:22 +0100 Subject: [PATCH 2/2] Use `map()` instead of for loops --- public/efy | 1 - src/components/PlaylistsPage.vue | 10 ++-------- 2 files changed, 2 insertions(+), 9 deletions(-) delete mode 160000 public/efy diff --git a/public/efy b/public/efy deleted file mode 160000 index 51f030d7..00000000 --- a/public/efy +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 51f030d755a9115f06341ecd78fbbf75ec600059 diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index a6cdb5a4..7383fd79 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -134,10 +134,7 @@ export default { version: 1, playlists: [], }; - let tasks = []; - for (var i = 0; i < this.playlists.length; i++) { - tasks.push(this.fetchPlaylistJson(this.playlists[i].id)); - } + let tasks = this.playlists.map(playlist => this.fetchPlaylistJson(playlist.id)); json.playlists = await Promise.all(tasks); this.download(JSON.stringify(json), "playlists.json", "application/json"); }, @@ -150,11 +147,8 @@ export default { // 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: [], + videos: playlist.relatedStreams.map(stream => "https://youtube.com" + stream.url), }; - for (var i = 0; i < playlist.relatedStreams.length; i++) { - playlistJson.videos.push("https://youtube.com" + playlist.relatedStreams[i].url); - } return playlistJson; }, async importPlaylists() {