@@ -33,19 +33,23 @@ def convert_image(f_or_path, saveto: str, thumbnail=False):
3333 subprocess .run (cmd , check = True , stderr = None if settings .debug else subprocess .DEVNULL )
3434
3535
36- def extract_thumbnail (path : Union [str , Path ], id : str , page : int , cache = False ) -> Path :
36+ def extract_thumbnail (path : Union [str , Path ], id : str , page : int , cache = False , cover = False ) -> Path :
3737 path = Path (path )
38- saveto = Path (settings .thumb ) / ( id + '.webp' ) if page == 1 else Path ( settings . thumb ) / id / f'{ page } .webp'
38+ saveto = Path (settings .thumb ) / id / f'{ page } .webp'
3939 if cache and saveto .exists ():
4040 return saveto .relative_to (settings .thumb )
4141 saveto .parent .mkdir (parents = True , exist_ok = True )
4242 if path .is_dir ():
4343 convert_image (sorted (filter (lambda p :p .suffix != '.txt' and not p .name .startswith ('.' ), path .iterdir ()))[page - 1 ], saveto , thumbnail = True )
44- return saveto .relative_to (settings .thumb )
4544 elif path .suffix == '.zip' :
4645 with ZipFile (path ) as z :
4746 with z .open (list (filter (lambda z_info : not z_info .is_dir (), z .infolist ()))[page - 1 ].filename ) as f :
4847 convert_image (f , saveto , thumbnail = True )
49- return saveto .relative_to (settings .thumb )
5048 else :
51- raise NotImplementedError
49+ raise NotImplementedError
50+ if cover :
51+ cover_path = Path (settings .cover ) / f'{ id } .webp'
52+ cover_path .parent .mkdir (parents = True , exist_ok = True )
53+ shutil .copy2 (saveto , cover_path )
54+ return cover_path .name
55+ return saveto .relative_to (settings .thumb )
0 commit comments