@@ -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 :
0 commit comments