mirror of
				https://github.com/9001/copyparty.git
				synced 2025-10-31 04:32:20 -06:00 
			
		
		
		
	epub: handle missing covers; closes #860
This commit is contained in:
		
							parent
							
								
									171ca985c8
								
							
						
					
					
						commit
						4177c1d9ed
					
				|  | @ -200,9 +200,10 @@ def au_unpk( | ||||||
| 
 | 
 | ||||||
|     except Exception as ex: |     except Exception as ex: | ||||||
|         if ret: |         if ret: | ||||||
|             t = "failed to decompress audio file %r: %r" |             t = "failed to decompress file %r: %r" | ||||||
|             log(t % (abspath, ex)) |             log(t % (abspath, ex)) | ||||||
|             wunlink(log, ret, vn.flags if vn else VF_CAREFUL) |             wunlink(log, ret, vn.flags if vn else VF_CAREFUL) | ||||||
|  |             return "" | ||||||
| 
 | 
 | ||||||
|         return abspath |         return abspath | ||||||
| 
 | 
 | ||||||
|  | @ -422,10 +423,17 @@ def get_cover_from_epub(log: "NamedLogger", abspath: str) -> Optional[IO[bytes]] | ||||||
|             # This might be an EPUB2 file, try the legacy way of specifying covers |             # This might be an EPUB2 file, try the legacy way of specifying covers | ||||||
|             coverimage_path = _get_cover_from_epub2(log, package_root, package_ns) |             coverimage_path = _get_cover_from_epub2(log, package_root, package_ns) | ||||||
| 
 | 
 | ||||||
|  |         if not coverimage_path: | ||||||
|  |             raise Exception("no cover inside epub") | ||||||
|  | 
 | ||||||
|         # This url is either absolute (in the .epub) or relative to the package document |         # This url is either absolute (in the .epub) or relative to the package document | ||||||
|         adjusted_cover_path = urljoin(rootfile_path, coverimage_path) |         adjusted_cover_path = urljoin(rootfile_path, coverimage_path) | ||||||
| 
 | 
 | ||||||
|         return z.open(adjusted_cover_path) |         try: | ||||||
|  |             return z.open(adjusted_cover_path) | ||||||
|  |         except KeyError: | ||||||
|  |             t = "epub: cover specified in package document, but doesn't exist: %s" | ||||||
|  |             log(t % (adjusted_cover_path,)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _get_cover_from_epub2( | def _get_cover_from_epub2( | ||||||
|  | @ -643,6 +651,9 @@ class MTag(object): | ||||||
|             return self._get(abspath) |             return self._get(abspath) | ||||||
| 
 | 
 | ||||||
|         ap = au_unpk(self.log, self.args.au_unpk, abspath) |         ap = au_unpk(self.log, self.args.au_unpk, abspath) | ||||||
|  |         if not ap: | ||||||
|  |             return {} | ||||||
|  | 
 | ||||||
|         ret = self._get(ap) |         ret = self._get(ap) | ||||||
|         if ap != abspath: |         if ap != abspath: | ||||||
|             wunlink(self.log, ap, VF_CAREFUL) |             wunlink(self.log, ap, VF_CAREFUL) | ||||||
|  | @ -748,6 +759,9 @@ class MTag(object): | ||||||
|             ap = abspath |             ap = abspath | ||||||
| 
 | 
 | ||||||
|         ret: dict[str, Any] = {} |         ret: dict[str, Any] = {} | ||||||
|  |         if not ap: | ||||||
|  |             return ret | ||||||
|  | 
 | ||||||
|         for tagname, parser in sorted(parsers.items(), key=lambda x: (x[1].pri, x[0])): |         for tagname, parser in sorted(parsers.items(), key=lambda x: (x[1].pri, x[0])): | ||||||
|             try: |             try: | ||||||
|                 cmd = [parser.bin, ap] |                 cmd = [parser.bin, ap] | ||||||
|  |  | ||||||
|  | @ -381,7 +381,7 @@ class ThumbSrv(object): | ||||||
|             else: |             else: | ||||||
|                 ap_unpk = abspath |                 ap_unpk = abspath | ||||||
| 
 | 
 | ||||||
|             if not bos.path.exists(tpath): |             if ap_unpk and not bos.path.exists(tpath): | ||||||
|                 tex = tpath.rsplit(".", 1)[-1] |                 tex = tpath.rsplit(".", 1)[-1] | ||||||
|                 want_mp3 = tex == "mp3" |                 want_mp3 = tex == "mp3" | ||||||
|                 want_opus = tex in ("opus", "owa", "caf") |                 want_opus = tex in ("opus", "owa", "caf") | ||||||
|  | @ -424,12 +424,14 @@ class ThumbSrv(object): | ||||||
|             except: |             except: | ||||||
|                 pass |                 pass | ||||||
| 
 | 
 | ||||||
|  |             conv_ok = False | ||||||
|             for fun in funs: |             for fun in funs: | ||||||
|                 try: |                 try: | ||||||
|                     if not png_ok and tpath.endswith(".png"): |                     if not png_ok and tpath.endswith(".png"): | ||||||
|                         raise Exception("png only allowed for waveforms") |                         raise Exception("png only allowed for waveforms") | ||||||
| 
 | 
 | ||||||
|                     fun(ap_unpk, ttpath, fmt, vn) |                     fun(ap_unpk, ttpath, fmt, vn) | ||||||
|  |                     conv_ok = True | ||||||
|                     break |                     break | ||||||
|                 except Exception as ex: |                 except Exception as ex: | ||||||
|                     msg = "%s could not create thumbnail of %r\n%s" |                     msg = "%s could not create thumbnail of %r\n%s" | ||||||
|  | @ -451,16 +453,20 @@ class ThumbSrv(object): | ||||||
|                         except: |                         except: | ||||||
|                             pass |                             pass | ||||||
| 
 | 
 | ||||||
|             if abspath != ap_unpk: |             if abspath != ap_unpk and ap_unpk: | ||||||
|                 wunlink(self.log, ap_unpk, vn.flags) |                 wunlink(self.log, ap_unpk, vn.flags) | ||||||
| 
 | 
 | ||||||
|             try: |             try: | ||||||
|                 atomic_move(self.log, ttpath, tpath, vn.flags) |                 atomic_move(self.log, ttpath, tpath, vn.flags) | ||||||
|             except Exception as ex: |             except Exception as ex: | ||||||
|                 if not os.path.exists(tpath): |                 if conv_ok and not os.path.exists(tpath): | ||||||
|                     t = "failed to move  [%s]  to  [%s]:  %r" |                     t = "failed to move  [%s]  to  [%s]:  %r" | ||||||
|                     self.log(t % (ttpath, tpath, ex), 3) |                     self.log(t % (ttpath, tpath, ex), 3) | ||||||
|                 pass |                 elif not conv_ok: | ||||||
|  |                     try: | ||||||
|  |                         open(tpath, "ab").close() | ||||||
|  |                     except: | ||||||
|  |                         pass | ||||||
| 
 | 
 | ||||||
|             untemp = [] |             untemp = [] | ||||||
|             with self.mutex: |             with self.mutex: | ||||||
|  | @ -682,7 +688,7 @@ class ThumbSrv(object): | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         c: Union[str, int] = "90" |         c: Union[str, int] = "90" | ||||||
|         t = "FFmpeg failed (probably a corrupt video file):\n" |         t = "FFmpeg failed (probably a corrupt file):\n" | ||||||
|         if ( |         if ( | ||||||
|             (not self.args.th_ff_jpg or time.time() - int(self.args.th_ff_jpg) < 60) |             (not self.args.th_ff_jpg or time.time() - int(self.args.th_ff_jpg) < 60) | ||||||
|             and cmd[-1].lower().endswith(b".webp") |             and cmd[-1].lower().endswith(b".webp") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue