From 63ac765e4145743ddcb5a9a3412c04dc7a18d439 Mon Sep 17 00:00:00 2001 From: Emmanuel Jemeni Date: Sat, 25 Feb 2023 22:32:47 +0100 Subject: [PATCH] fix(ebook/__init__.py): Leech will now ignore empty image tags (because apparently that's a thing). feat(ebook/__init__.py): Leech print out more information about the images it is downloading. The number of images in each chapter and the image downloading currently. --- ebook/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ebook/__init__.py b/ebook/__init__.py index cf7ba9f..910d0b1 100644 --- a/ebook/__init__.py +++ b/ebook/__init__.py @@ -89,7 +89,15 @@ def chapter_html(story, titleprefix=None, normalize=False): chapter, titleprefix=title, normalize=normalize)) else: soup = BeautifulSoup(chapter.contents, 'html5lib') - for count, img in enumerate(soup.find_all('img')): + all_images = soup.find_all('img') + len_of_all_images = len(all_images) + print(f"\nFound {len_of_all_images} images in chapter {i}\n") + + for count, img in enumerate(all_images): + if not img.has_attr('src'): + print(f"Image {count} has no src attribute, skipping...") + continue + print(f"Downloading image {count+1} out of {len_of_all_images} from chapter {i}") img_contents = get_image_from_url(img['src']).read() chapter.images.append(Image( path=f"images/ch{i}_leechimage_{count}.png",