mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
fix: fixed an issue where only the first 100 songs in a playlist were downloaded (#1329)
This commit is contained in:
@ -361,7 +361,7 @@ async function iterableStreamToTargetFile(
|
|||||||
|
|
||||||
ffmpeg.setProgress(({ ratio }) => {
|
ffmpeg.setProgress(({ ratio }) => {
|
||||||
sendFeedback(`Converting: ${Math.floor(ratio * 100)}%`, ratio);
|
sendFeedback(`Converting: ${Math.floor(ratio * 100)}%`, ratio);
|
||||||
increasePlaylistProgress(0.15 + ratio * 0.85);
|
increasePlaylistProgress(0.15 + (ratio * 0.85));
|
||||||
});
|
});
|
||||||
|
|
||||||
const safeVideoNameWithExtension = `${safeVideoName}.${extension}`;
|
const safeVideoNameWithExtension = `${safeVideoName}.${extension}`;
|
||||||
@ -468,8 +468,12 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
|||||||
console.log(`trying to get playlist ID: '${playlistId}'`);
|
console.log(`trying to get playlist ID: '${playlistId}'`);
|
||||||
sendFeedback('Getting playlist info…');
|
sendFeedback('Getting playlist info…');
|
||||||
let playlist: Playlist;
|
let playlist: Playlist;
|
||||||
|
const items: YTNodes.MusicResponsiveListItem[] = [];
|
||||||
try {
|
try {
|
||||||
playlist = await yt.music.getPlaylist(playlistId);
|
playlist = await yt.music.getPlaylist(playlistId);
|
||||||
|
if (playlist?.items) {
|
||||||
|
items.push(...playlist.items.as(YTNodes.MusicResponsiveListItem));
|
||||||
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
sendError(
|
sendError(
|
||||||
Error(
|
Error(
|
||||||
@ -485,13 +489,6 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
|||||||
sendError(new Error('Playlist is empty'));
|
sendError(new Error('Playlist is empty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = playlist.items!.as(YTNodes.MusicResponsiveListItem);
|
|
||||||
if (items.length === 1) {
|
|
||||||
sendFeedback('Playlist has only one item, downloading it directly');
|
|
||||||
await downloadSongFromId(items.at(0)!.id!);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalPlaylistTitle = playlist.header?.title?.text;
|
const normalPlaylistTitle = playlist.header?.title?.text;
|
||||||
const playlistTitle =
|
const playlistTitle =
|
||||||
normalPlaylistTitle ??
|
normalPlaylistTitle ??
|
||||||
@ -502,6 +499,19 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
|||||||
'NO_TITLE';
|
'NO_TITLE';
|
||||||
const isAlbum = !normalPlaylistTitle;
|
const isAlbum = !normalPlaylistTitle;
|
||||||
|
|
||||||
|
while (playlist.has_continuation) {
|
||||||
|
playlist = await playlist.getContinuation();
|
||||||
|
if (playlist?.items) {
|
||||||
|
items.push(...playlist.items.as(YTNodes.MusicResponsiveListItem));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items.length === 1) {
|
||||||
|
sendFeedback('Playlist has only one item, downloading it directly');
|
||||||
|
await downloadSongFromId(items.at(0)!.id!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let safePlaylistTitle = filenamify(playlistTitle, { replacement: ' ' });
|
let safePlaylistTitle = filenamify(playlistTitle, { replacement: ' ' });
|
||||||
if (!is.macOS()) {
|
if (!is.macOS()) {
|
||||||
safePlaylistTitle = safePlaylistTitle.normalize('NFC');
|
safePlaylistTitle = safePlaylistTitle.normalize('NFC');
|
||||||
@ -542,7 +552,7 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
|
|||||||
|
|
||||||
const increaseProgress = (itemPercentage: number) => {
|
const increaseProgress = (itemPercentage: number) => {
|
||||||
const currentProgress = (counter - 1) / (items.length ?? 1);
|
const currentProgress = (counter - 1) / (items.length ?? 1);
|
||||||
const newProgress = currentProgress + progressStep * itemPercentage;
|
const newProgress = currentProgress + (progressStep * itemPercentage);
|
||||||
win.setProgressBar(newProgress);
|
win.setProgressBar(newProgress);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user