diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 2f74bc48..d4fcc5b7 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -191,16 +191,27 @@ export default { window.location.reload(); }, async importPlaylistFile(file) { - let text = await file.text(); + let text = (await file.text()).trim(); let tasks = []; // list of playlists exported from Piped if (file.name.slice(-4).toLowerCase() == ".csv") { const lines = text.split("\n"); - const playlistName = lines[1].split(",")[4]; + + // old format: first two lines contain playlist info (e.g. name) in CSV format + // new format: no information about playlist like name, ... + // video list has two columns: videoId and date of addition + const playlistInfo = lines[1].split(","); + let videoListStartIndex = 0; + let playlistName = null; + if (playlistInfo.length > 2) { + playlistName = playlistInfo[4]; + videoListStartIndex = 4; + } + const playlist = { - name: playlistName != "" ? playlistName : new Date().toJSON(), + name: playlistName ?? new Date().toJSON(), videos: lines - .slice(4, lines.length) + .slice(videoListStartIndex, lines.length) .filter(line => line != "") .slice(1) .map(line => `https://youtube.com/watch?v=${line.split(",")[0]}`), diff --git a/src/main.js b/src/main.js index dadce40e..a723ddea 100644 --- a/src/main.js +++ b/src/main.js @@ -314,7 +314,7 @@ const mixin = { var store = tx.objectStore("playlist_videos"); const req = store.openCursor(videoId); req.onsuccess = e => { - resolve(e.target.result.value); + resolve(e.target.result?.value); }; }); }, @@ -351,7 +351,7 @@ const mixin = { const playlist = await this.getLocalPlaylist(playlistId); const videoIds = JSON.parse(playlist.videoIds); const videosFuture = videoIds.map(videoId => this.getLocalPlaylistVideo(videoId)); - playlist.relatedStreams = await Promise.all(videosFuture); + playlist.relatedStreams = (await Promise.all(videosFuture)).filter(video => video !== undefined); return playlist; } @@ -468,6 +468,7 @@ const mixin = { playlist.thumbnail = streamInfos[0].thumbnail || streamInfos[0].thumbnailUrl; this.createOrUpdateLocalPlaylist(playlist); for (let i in videoIds) { + if (streamInfos[i].error) continue; this.createLocalPlaylistVideo(videoIds[i], streamInfos[i]); } return { message: "ok" };