handle emoji thumbnail

This commit is contained in:
Yuxin Wu
2020-06-27 16:32:07 -07:00
parent 4dc13a16f7
commit d6d2aaea55
2 changed files with 7 additions and 10 deletions
+2 -2
View File
@@ -18,7 +18,7 @@ def parse_wechat_audio_file(file_name):
try:
return do_parse_wechat_audio_file(file_name)
except Exception as e:
logger.exception("Error when parsing audio file {}".format(file_name))
logger.error(f"Error when parsing audio file {file_name}: {str(e)}")
return "", 0
def do_parse_wechat_audio_file(file_name):
@@ -56,7 +56,7 @@ def do_parse_wechat_audio_file(file_name):
subproc_succ('sox -r 24000 -e signed -b 16 -c 1 {} {}'.format(raw_file, mp3_file))
os.unlink(raw_file)
else:
raise NotImplementedError("Unsupported Audio Format! This is a bug!")
raise NotImplementedError("Audio file format cannot be recognized.")
mp3_string = get_file_b64(mp3_file)
os.unlink(mp3_file)
return mp3_string, duration
+5 -8
View File
@@ -204,8 +204,7 @@ class Resource(object):
"""
path = os.path.join(self.emoji_dir, pack_id or '')
candidates = glob.glob(os.path.join(path, '{}*'.format(md5)))
candidates = [k for k in candidates if not k.endswith('_thumb') \
and not re.match('.*_[0-9]+$', k)]
candidates = [k for k in candidates if not re.match('.*_[0-9]+$', k)]
def try_use(f):
if not f: return None
@@ -213,7 +212,7 @@ class Resource(object):
return None
return f[0]
candidates = [k for k in candidates if (allow_cover or not k.endswith('_cover'))]
candidates = [k for k in candidates if (allow_cover or (not k.endswith('_cover') and not k.endswith('_thumb')))]
for cand in candidates:
if imghdr.what(cand):
@@ -228,10 +227,8 @@ class Resource(object):
""" :returns: (b64 unicode img, format)"""
assert md5, md5
if md5 in self.parser.internal_emojis:
# TODO this seems broken
emoji_img, format = self._get_internal_emoji(self.parser.internal_emojis[md5])
logger.warn("Cannot get emoji {}".format(md5))
return None, None
return emoji_img, format
else:
# check cache
img, format = self.emoji_cache.query(md5)
@@ -256,8 +253,8 @@ class Resource(object):
if format:
return emoji_img, format
# first 1k in emoji is encrypted
logger.warn("Cannot get emoji {} in {}".format(md5, group))
# TODO: first 1k in emoji is encrypted
logger.warn("Cannot get emoji {} in group {}".format(md5, group))
return None, None
def get_video(self, videoid):