diff --git a/dump-html.py b/dump-html.py index 4a721fa..bb947df 100755 --- a/dump-html.py +++ b/dump-html.py @@ -46,7 +46,7 @@ if __name__ == '__main__': render = HTMLRender(parser, res) htmls = render.render_msgs(msgs) - os.makedirs(os.path.dirname(output_file), exist_ok=True) + os.makedirs(os.path.dirname(os.path.abspath(output_file)), exist_ok=True) if len(htmls) == 1: with open(output_file, 'w') as f: f.write(htmls[0]) diff --git a/wechat/emoji.py b/wechat/emoji.py index ff9b6bf..ba9770e 100644 --- a/wechat/emoji.py +++ b/wechat/emoji.py @@ -15,7 +15,7 @@ from .common.textutil import md5 as get_md5_hex, get_file_b64, get_file_md5 LIB_PATH = os.path.dirname(os.path.abspath(__file__)) -DEFAULT_EMOJI_CACHE = os.path.join(LIB_PATH, '..', 'emoji.cache.pkl') +DEFAULT_EMOJI_CACHE = os.path.join(LIB_PATH, '..', 'emoji.cache') logger = logging.getLogger(__name__) @@ -39,7 +39,7 @@ class EmojiReader: resource_dir: path to resource/ parser: Database parser cache_file: a cache file to store emoji downloaded from URLs. - default to a emoji.cache.pkl file under wechat-dump. + default to a emoji.cache file under wechat-dump. """ self.emoji_dir = Path(resource_dir) / 'emoji' assert self.emoji_dir.is_dir(), self.emoji_dir @@ -89,7 +89,7 @@ class EmojiReader: return img, format else: emoji_in_table = emoji_info is not None - msg = "not in database" if not emoji_in_table else f"group={subdir}" + msg = "not in database" if not emoji_in_table else f"group='{subdir}'" logger.warning(f"Cannot find emoji {md5}: {msg}") return None, None @@ -132,11 +132,14 @@ class EmojiReader: content = self._decode_emoji(fname) try: data_md5 = get_md5_hex(content) - assert data_md5 == md5 + if data_md5 != md5: + if content.startswith(b"wxgf"): + raise ValueError("Unsupported mysterious image format: wxgf") + raise ValueError("Decoded data mismatch md5!") im = Image.open(io.BytesIO(content)) return (base64.b64encode(content).decode('ascii'), im.format.lower()) - except: - logger.exception(f"Error decoding emoji {fname}.") + except Exception as e: + logger.error(f"Error decoding emoji {fname} : {str(e)}") def get_data_fallback(fname): if not imghdr.what(fname): @@ -208,4 +211,4 @@ if __name__ == "__main__": encurl = 'http://emoji.qpic.cn/wx_emoji/CQmBgayyMuvscRVEKN9s4HyTjKVU9iacqqhyCpdtqOVcCql5JaibjDFg/' enckey = '8ba7f51f9f3ac58cf8ed937fc90200a6' b64, format = EmojiReader._fetch(Dummy(), md5, None, encurl, enckey) - print("format=", format) \ No newline at end of file + print("format=", format)