Skip to content

Commit

Permalink
fix: import of youtube playlists (and workaround for deleted/private …
Browse files Browse the repository at this point in the history
…videos) when importing without account (#3670)
  • Loading branch information
Bnyro authored Jun 14, 2024
1 parent 1c824b1 commit a8fb742
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/components/PlaylistsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`),
Expand Down
5 changes: 3 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
});
},
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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" };
Expand Down

0 comments on commit a8fb742

Please sign in to comment.