Skip to content

Commit ed36fcf

Browse files
committed
feat!: Released v1.0.1
1 parent 16dfde2 commit ed36fcf

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.1] - 2023-05-11
9+
10+
### Added
11+
- Improved logging by adding an overview of downloaded images.
12+
- Added a Changelog
13+
14+
## [1.0.0] - 2023-05-08
15+
- Released FicImageScript
16+
17+
18+
[1.0.1]: https://github.com/Jemeni11/FicImage/compare/v1.0.0...v1.0.1
19+
[1.0.0]: https://github.com/Jemeni11/FicImage/releases/tag/v1.0.0

FicImage/main.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def main() -> None:
1616
parser.add_argument("-c", "--config_file_path", help="The path to the ficimage.json file.")
1717
parser.add_argument("-d", "--debug", help="Enable debug mode.", action="store_true")
1818
args = parser.parse_args()
19-
19+
2020
path_to_epub = args.path_to_epub
2121
config_file_path = args.config_file_path
2222
debug = args.debug
23-
23+
2424
try:
2525
book = epub.read_epub(path_to_epub)
2626
print(f'Opened {path_to_epub}')
27-
27+
2828
(config_file_exists, config_file_location) = config_check(config_file_path)
2929
if config_file_exists:
3030
ficimage_config = load_config_json(config_file_location)
@@ -35,15 +35,18 @@ def main() -> None:
3535
if str(default_image_format_config).lower() not in ("jpg", "jpeg", "png"):
3636
default_image_format_config = "JPEG"
3737
max_image_size_config: int = ficimage_config.get("max_image_size", 1_000_000)
38-
38+
3939
file_name = path_to_epub.split('/')[-1].split('.')[0]
40-
40+
images_downloaded = {}
41+
4142
for item in book.get_items_of_type(ebooklib.ITEM_DOCUMENT):
4243
try:
4344
soup = BeautifulSoup(item.content, "lxml-xml")
4445
p_tags = soup.find_all('p')
4546
images = [i for i in p_tags if '[img:' in i.text]
4647
print(f'Found {len(images)} images in {item.file_name}')
48+
item_file_name = item.file_name.split('.')[0]
49+
images_downloaded[item.file_name] = [0, len(images)]
4750
# Clean up the images link
4851
# Right now they look like this: <p>[img: <a
4952
# href="https://i.imgur.com/ABCDEF.jpg" rel="noopener noreferrer">data:image/gif;base64,R0lGODlhA</a>]</p>
@@ -53,11 +56,9 @@ def main() -> None:
5356
if image is None:
5457
print("NoneType, Skipping")
5558
else:
56-
item_file_name = item.file_name.split('.')[0]
5759
image_link = image.a['href']
5860
print(f"[{item_file_name}] Image {images.index(image) + 1} "
5961
f"(out of {len(images)}). Source: {image_link}")
60-
6162
try:
6263
(
6364
image_content,
@@ -70,12 +71,13 @@ def main() -> None:
7071
max_image_size=max_image_size_config,
7172
debug=debug
7273
)
74+
images_downloaded[item.file_name][0] += 1
7375
image_path = f"images/" \
7476
f"{item_file_name}_image_{images.index(image)}.{image_extension.lower()}"
7577
new_image = f"<img alt='Image {images.index(image)} from {item.file_name}' " \
7678
f"style='text-align: center; margin: 2em auto; display: block;'" \
7779
f" src='{image_path}' />"
78-
80+
7981
img = epub.EpubItem(
8082
uid=f"{item_file_name}_{images.index(image)}",
8183
file_name=image_path,
@@ -91,10 +93,25 @@ def main() -> None:
9193
print(f'Error while parsing images: {e}')
9294
except TypeError:
9395
print("NoneType error, skipping ...")
94-
96+
9597
try:
9698
epub.write_epub(f"[FicImage]{file_name}.epub", book)
99+
total_number_of_images_downloaded = 0
100+
number_of_all_images_found = 0
101+
for _, chapter_image_list in images_downloaded.items():
102+
total_number_of_images_downloaded += chapter_image_list[0]
103+
number_of_all_images_found += chapter_image_list[1]
104+
97105
print(f'Wrote [FicImage]{file_name}.epub')
106+
print(f"Image overview of {file_name}")
107+
print("=" * 54)
108+
for k, v in images_downloaded.items():
109+
print(f"{k}{' ' * (18 - len(k))}\t{v[0]} out of {v[1]} images downloaded")
110+
print("=" * 54)
111+
print(f"Total images downloaded: {total_number_of_images_downloaded}"
112+
f" out of {number_of_all_images_found}")
113+
print("=" * 54)
114+
98115
except Exception as e:
99116
print(f'Error while writing epub: {e}')
100117
except FileNotFoundError:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "FicImageScript"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = [
55
{ name="Emmanuel C. Jemeni", email="[email protected]" }
66
]

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="FicImageScript",
8-
version="1.0.0",
8+
version="1.0.1",
99
author="Emmanuel C. Jemeni",
1010
author_email="[email protected]",
1111
description="FicImage is an application designed to enhance the reading experience of FicHub epubs.",

0 commit comments

Comments
 (0)