Add import from YouTube CSV

This commit is contained in:
Bnyro 2023-01-01 19:57:00 +01:00
parent 956b68c333
commit 58cd6f8f37
2 changed files with 24 additions and 7 deletions

1
public/efy Submodule

@ -0,0 +1 @@
Subproject commit 51f030d755a9115f06341ecd78fbbf75ec600059

View File

@ -160,21 +160,37 @@ export default {
async importPlaylists() { async importPlaylists() {
const file = this.$refs.fileSelector.files[0]; const file = this.$refs.fileSelector.files[0];
let text = await file.text(); let text = await file.text();
let playlists = JSON.parse(text).playlists; let tasks = [];
if (!playlists.length) { // 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")); alert(this.$t("actions.no_valid_playlists"));
return; return;
} }
let tasks = [];
for (var i = 0; i < playlists.length; i++) {
tasks.push(this.createPlaylistWithVideos(playlists[i]));
}
await Promise.all(tasks); await Promise.all(tasks);
window.location.reload(); window.location.reload();
}, },
async createPlaylistWithVideos(playlist) { async createPlaylistWithVideos(playlist) {
let newPlaylist = await this.createPlaylist(playlist.name); let newPlaylist = await this.createPlaylist(playlist.name);
console.log(newPlaylist);
let videoIds = playlist.videos.map(url => url.substr(-11)); let videoIds = playlist.videos.map(url => url.substr(-11));
await this.addVideosToPlaylist(newPlaylist.playlistId, videoIds); await this.addVideosToPlaylist(newPlaylist.playlistId, videoIds);
}, },