From 870a1852bf9406b02f4e14bf2ee44ac165197aa6 Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Sat, 18 Jun 2016 23:37:04 -0700 Subject: [PATCH] avoid using cover, and use compressed emoji.cache --- README.md | 2 +- emoji-cache-tool.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ wechat/res.py | 7 ++++--- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 emoji-cache-tool.py diff --git a/README.md b/README.md index 94587e7..2c96ba7 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Note that commands involving `./android-interact.sh` are meant to be run on the ``` + What you'll need in the end is a `resource` directory with the following subdir: `emoji,image2,sfs,video,voice2`. -+ (Optional) Download the emoji cache from [here](https://github.com/ppwwyyxx/wechat-dump/releases/download/0.1/emoji.cache) ++ (Optional) Download uncompress the emoji cache from [here](https://github.com/ppwwyyxx/wechat-dump/releases/download/0.1/emoji.cache) and put it under `wechat-dump`. This will avoid downloading lots of emojis in rendering. #### Run: diff --git a/emoji-cache-tool.py b/emoji-cache-tool.py new file mode 100755 index 0000000..d917334 --- /dev/null +++ b/emoji-cache-tool.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# File: emoji-cache-tool.py +# Author: Yuxin Wu + +import cPickle as pickle +import sys +import os +import imghdr +import base64 + +if __name__ == '__main__': + if len(sys.argv) != 3: + print """\ +Usage: + {} unpack output-dir + {} pack input-dir +""".format(sys.argv[0], sys.argv[0]) + sys.exit(1) + + if sys.argv[1] == 'unpack': + with open('emoji.cache') as f: + dic = pickle.load(f) + outdir = sys.argv[2] + assert os.path.isdir(outdir) + for md5, img in dic.iteritems(): + name = os.path.join(outdir, md5 + '.' + img[1].lower()) + print name + with open(name, 'wb') as f: + f.write(base64.decodestring(img[0])) + elif sys.argv[1] == 'pack': + ret = {} + indir = sys.argv[2] + files = os.listdir(indir) + for fname in files: + try: + md5, format = fname.split('.') + except: + print "Unable to parse", fname + continue + with open(os.path.join(indir, fname)) as f: + b64 = base64.encodestring(f.read()) + ret[md5] = (b64, format) + with open('emoji.cache', 'wb') as f: + pickle.dump(ret, f) diff --git a/wechat/res.py b/wechat/res.py index 043017b..51af046 100644 --- a/wechat/res.py +++ b/wechat/res.py @@ -214,9 +214,10 @@ class Resource(object): if f: return get_file_b64(f), imghdr.what(f) - f = try_use([k for k in candidates if k.endswith('_cover')]) - if f: - return get_file_b64(f), imghdr.what(f) + # don't try do use cover anymore. cover is not animated + #f = try_use([k for k in candidates if k.endswith('_cover')]) + #if f: + #return get_file_b64(f), imghdr.what(f) return None, None def _get_internal_emoji(self, fname):