mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-30 18:43:17 +00:00
fix: import of youtube playlists (and workaround for deleted/private videos) when importing without account (#3670)
This commit is contained in:
parent
1c824b1dad
commit
a8fb7421e6
@ -191,16 +191,27 @@ export default {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
},
|
},
|
||||||
async importPlaylistFile(file) {
|
async importPlaylistFile(file) {
|
||||||
let text = await file.text();
|
let text = (await file.text()).trim();
|
||||||
let tasks = [];
|
let tasks = [];
|
||||||
// list of playlists exported from Piped
|
// list of playlists exported from Piped
|
||||||
if (file.name.slice(-4).toLowerCase() == ".csv") {
|
if (file.name.slice(-4).toLowerCase() == ".csv") {
|
||||||
const lines = text.split("\n");
|
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 = {
|
const playlist = {
|
||||||
name: playlistName != "" ? playlistName : new Date().toJSON(),
|
name: playlistName ?? new Date().toJSON(),
|
||||||
videos: lines
|
videos: lines
|
||||||
.slice(4, lines.length)
|
.slice(videoListStartIndex, lines.length)
|
||||||
.filter(line => line != "")
|
.filter(line => line != "")
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.map(line => `https://youtube.com/watch?v=${line.split(",")[0]}`),
|
.map(line => `https://youtube.com/watch?v=${line.split(",")[0]}`),
|
||||||
|
@ -314,7 +314,7 @@ const mixin = {
|
|||||||
var store = tx.objectStore("playlist_videos");
|
var store = tx.objectStore("playlist_videos");
|
||||||
const req = store.openCursor(videoId);
|
const req = store.openCursor(videoId);
|
||||||
req.onsuccess = e => {
|
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 playlist = await this.getLocalPlaylist(playlistId);
|
||||||
const videoIds = JSON.parse(playlist.videoIds);
|
const videoIds = JSON.parse(playlist.videoIds);
|
||||||
const videosFuture = videoIds.map(videoId => this.getLocalPlaylistVideo(videoId));
|
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;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,6 +468,7 @@ const mixin = {
|
|||||||
playlist.thumbnail = streamInfos[0].thumbnail || streamInfos[0].thumbnailUrl;
|
playlist.thumbnail = streamInfos[0].thumbnail || streamInfos[0].thumbnailUrl;
|
||||||
this.createOrUpdateLocalPlaylist(playlist);
|
this.createOrUpdateLocalPlaylist(playlist);
|
||||||
for (let i in videoIds) {
|
for (let i in videoIds) {
|
||||||
|
if (streamInfos[i].error) continue;
|
||||||
this.createLocalPlaylistVideo(videoIds[i], streamInfos[i]);
|
this.createLocalPlaylistVideo(videoIds[i], streamInfos[i]);
|
||||||
}
|
}
|
||||||
return { message: "ok" };
|
return { message: "ok" };
|
||||||
|
Loading…
Reference in New Issue
Block a user