diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..df5b017 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.1] - 2023-05-11 + +### Added +- Improved logging by adding an overview of downloaded images. +- Added a Changelog + +## [1.0.0] - 2023-05-08 +- Released FicImageScript + + +[1.0.1]: https://github.com/Jemeni11/FicImage/compare/v1.0.0...v1.0.1 +[1.0.0]: https://github.com/Jemeni11/FicImage/releases/tag/v1.0.0 diff --git a/FicImage/main.py b/FicImage/main.py index 2053b95..a2482b9 100644 --- a/FicImage/main.py +++ b/FicImage/main.py @@ -16,15 +16,15 @@ def main() -> None: parser.add_argument("-c", "--config_file_path", help="The path to the ficimage.json file.") parser.add_argument("-d", "--debug", help="Enable debug mode.", action="store_true") args = parser.parse_args() - + path_to_epub = args.path_to_epub config_file_path = args.config_file_path debug = args.debug - + try: book = epub.read_epub(path_to_epub) print(f'Opened {path_to_epub}') - + (config_file_exists, config_file_location) = config_check(config_file_path) if config_file_exists: ficimage_config = load_config_json(config_file_location) @@ -35,15 +35,18 @@ def main() -> None: if str(default_image_format_config).lower() not in ("jpg", "jpeg", "png"): default_image_format_config = "JPEG" max_image_size_config: int = ficimage_config.get("max_image_size", 1_000_000) - + file_name = path_to_epub.split('/')[-1].split('.')[0] - + images_downloaded = {} + for item in book.get_items_of_type(ebooklib.ITEM_DOCUMENT): try: soup = BeautifulSoup(item.content, "lxml-xml") p_tags = soup.find_all('p') images = [i for i in p_tags if '[img:' in i.text] print(f'Found {len(images)} images in {item.file_name}') + item_file_name = item.file_name.split('.')[0] + images_downloaded[item.file_name] = [0, len(images)] # Clean up the images link # Right now they look like this:

[img: data:image/gif;base64,R0lGODlhA]

@@ -53,11 +56,9 @@ def main() -> None: if image is None: print("NoneType, Skipping") else: - item_file_name = item.file_name.split('.')[0] image_link = image.a['href'] print(f"[{item_file_name}] Image {images.index(image) + 1} " f"(out of {len(images)}). Source: {image_link}") - try: ( image_content, @@ -70,12 +71,13 @@ def main() -> None: max_image_size=max_image_size_config, debug=debug ) + images_downloaded[item.file_name][0] += 1 image_path = f"images/" \ f"{item_file_name}_image_{images.index(image)}.{image_extension.lower()}" new_image = f"Image {images.index(image)} from {item.file_name}" - + img = epub.EpubItem( uid=f"{item_file_name}_{images.index(image)}", file_name=image_path, @@ -91,10 +93,25 @@ def main() -> None: print(f'Error while parsing images: {e}') except TypeError: print("NoneType error, skipping ...") - + try: epub.write_epub(f"[FicImage]{file_name}.epub", book) + total_number_of_images_downloaded = 0 + number_of_all_images_found = 0 + for _, chapter_image_list in images_downloaded.items(): + total_number_of_images_downloaded += chapter_image_list[0] + number_of_all_images_found += chapter_image_list[1] + print(f'Wrote [FicImage]{file_name}.epub') + print(f"Image overview of {file_name}") + print("=" * 54) + for k, v in images_downloaded.items(): + print(f"{k}{' ' * (18 - len(k))}\t{v[0]} out of {v[1]} images downloaded") + print("=" * 54) + print(f"Total images downloaded: {total_number_of_images_downloaded}" + f" out of {number_of_all_images_found}") + print("=" * 54) + except Exception as e: print(f'Error while writing epub: {e}') except FileNotFoundError: diff --git a/pyproject.toml b/pyproject.toml index b17dbe7..e018502 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "FicImageScript" -version = "1.0.0" +version = "1.0.1" authors = [ { name="Emmanuel C. Jemeni", email="jemenichinonso11@gmail.com" } ] diff --git a/setup.py b/setup.py index ded1418..f594e77 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="FicImageScript", - version="1.0.0", + version="1.0.1", author="Emmanuel C. Jemeni", author_email="jemenichinonso11@gmail.com", description="FicImage is an application designed to enhance the reading experience of FicHub epubs.",