Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed an issue where only the first 100 songs in a playlist were downloaded #1329

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/plugins/downloader/back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ async function iterableStreamToTargetFile(

ffmpeg.setProgress(({ ratio }) => {
sendFeedback(`Converting: ${Math.floor(ratio * 100)}%`, ratio);
increasePlaylistProgress(0.15 + ratio * 0.85);
increasePlaylistProgress(0.15 + (ratio * 0.85));
});

const safeVideoNameWithExtension = `${safeVideoName}.${extension}`;
Expand Down Expand Up @@ -468,8 +468,12 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
console.log(`trying to get playlist ID: '${playlistId}'`);
sendFeedback('Getting playlist info…');
let playlist: Playlist;
const items: YTNodes.MusicResponsiveListItem[] = [];
try {
playlist = await yt.music.getPlaylist(playlistId);
if (playlist?.items) {
items.push(...playlist.items.as(YTNodes.MusicResponsiveListItem));
}
} catch (error: unknown) {
sendError(
Error(
Expand All @@ -485,13 +489,6 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
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 playlistTitle =
normalPlaylistTitle ??
Expand All @@ -502,6 +499,19 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
'NO_TITLE';
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: ' ' });
if (!is.macOS()) {
safePlaylistTitle = safePlaylistTitle.normalize('NFC');
Expand Down Expand Up @@ -542,7 +552,7 @@ export async function downloadPlaylist(givenUrl?: string | URL) {

const increaseProgress = (itemPercentage: number) => {
const currentProgress = (counter - 1) / (items.length ?? 1);
const newProgress = currentProgress + progressStep * itemPercentage;
const newProgress = currentProgress + (progressStep * itemPercentage);
win.setProgressBar(newProgress);
};

Expand Down
Loading