diff --git a/src/tts_tools/libtts.py b/src/tts_tools/libtts.py index 9a08f32..d420399 100644 --- a/src/tts_tools/libtts.py +++ b/src/tts_tools/libtts.py @@ -141,13 +141,19 @@ def get_fs_path(path, url): elif is_image(path, url): # TTS appears to perform some weird heuristics when determining # the file suffix. ._. + png_filename = recoded_name + ".png" + png_fullPath = os.path.join(IMGPATH, png_filename) + jpg_filename = recoded_name + ".jpg" + jpg_fullPath = os.path.join(IMGPATH, jpg_filename) + if os.path.isfile(png_fullPath): + return png_fullPath + elif os.path.isfile(jpg_fullPath): + return jpg_fullPath + if url.find(".png") > 0: - file_suffix = ".png" + return png_fullPath else: - file_suffix = ".jpg" - filename = recoded_name + file_suffix - return os.path.join(IMGPATH, filename) - + return jpg_fullPath else: errstr = ( "Do not know how to generate path for " diff --git a/src/tts_tools/prefetch/__init__.py b/src/tts_tools/prefetch/__init__.py index f7d48d0..b5bf7f9 100644 --- a/src/tts_tools/prefetch/__init__.py +++ b/src/tts_tools/prefetch/__init__.py @@ -144,6 +144,18 @@ def content_expected(mime): done.add(url) continue + if outfile_name.endswith('.png'): + jpg_path = os.path.splitext(outfile_name)[0] + '.jpg' + if os.path.isfile(jpg_path) and not refetch: + done.add(url) + continue + + if outfile_name.endswith('.jpg'): + jpg_path = os.path.splitext(outfile_name)[0] + '.png' + if os.path.isfile(jpg_path) and not refetch: + done.add(url) + continue + print("{} ".format(url), end="", flush=True) if dry_run: @@ -187,6 +199,11 @@ def content_expected(mime): print(size_msg, end="", flush=True) content_type = response.getheader("Content-Type", "").strip() + if content_type == "image/jpeg" or content_type == "image/jpg": + outfile_name = os.path.splitext(outfile_name)[0] + '.jpg' + if content_type == "image/png": + outfile_name = os.path.splitext(outfile_name)[0] + '.png' + is_expected = not content_type or content_expected(content_type) if not (is_expected or ignore_content_type): print_err(