josephrcox / easy-reddit-downloader

Simple headless Reddit post downloader
MIT License
70 stars 9 forks source link

if the post have many images it well download url not images #91

Closed kigy1 closed 3 months ago

kigy1 commented 5 months ago

thanks for your work

this how to fix it edit this code

for (const child of data.data.children) { const post = child.data; // Check if the post contains a gallery if (post.is_gallery && post.media_metadata) { Object.entries(post.mediametadata).forEach(async ([id, media]) => { if (media && media.s && media.s.u) { const imageUrl = media.s.u.replace(/&/g, '&'); const fileType = imageUrl.split('.').pop().split('?')[0]; const fileName = `${sanitizeFileName(post.title)}${id}.${fileType}; const filePath =${downloadDirectory}/${fileName}`;

            try {
                await downloadMediaFile(imageUrl, filePath);
                console.log(`Downloaded image: ${filePath}`);
            } catch (error) {
                console.error(`Failed to download image: ${error}`);
            }
        }
    });
} else {
    // Code for handling other types of posts
    await sleep();
    try {
        await downloadPost(post);
    } catch (e) {
        log(e, true);
    }
}

} } catch (error) { // throw the error throw error; } }

but after that this Error: EMFILE: too many open files, open also it is loops and download the file again and again

josephrcox commented 3 months ago

Should be closed with #94