Add support for new avatar storage (#50)

* Add support for new avatar storage,modify the README and android-interact.sh

* Show the nickname for chatroom, fix the IOError in avatar.py

* style change
This commit is contained in:
futurewrg
2017-11-29 01:34:51 -08:00
committed by Yuxin Wu
parent 265b57755d
commit dcad5ed99d
8 changed files with 32 additions and 13 deletions
+2 -2
View File
@@ -73,7 +73,7 @@ pip install --user --pre pysox
If things still don't work, you can try the [password cracker](https://github.com/chg-hou/EnMicroMsg.db-Password-Cracker)
to brute-force the password.
+ Copy the WeChat user resource directory `/mnt/sdcard/tencent/MicroMsg/${userid}/{emoji,image2,sfs,video,voice2}` from the phone to the `resource` directory:
+ Copy the WeChat user resource directory `/mnt/sdcard/tencent/MicroMsg/${userid}/{avatar,emoji,image2,sfs,video,voice2}` from the phone to the `resource` directory:
+ `./android-interact.sh res`
+ You might need to change `RES_DIR` in the script if the default is incorrect on your phone.
+ This can take a __very long__ time. Some manual ways to do it faster:
@@ -87,7 +87,7 @@ pip install --user --pre pysox
base64 -di | tar xzf -
```
+ What you'll need in the end is a `resource` directory with the following subdir: `emoji,image2,sfs,video,voice2`.
+ What you'll need in the end is a `resource` directory with the following subdir: `avatar,emoji,image2,sfs,video,voice2`.
+ (Optional) Download the emoji cache from [here](https://github.com/ppwwyyxx/wechat-dump/releases/download/0.1/emoji.cache.tar.bz2)
and put it under `resource/emoji`. This will avoid downloading too many emojis during rendering.
+1 -1
View File
@@ -53,7 +53,7 @@ elif [[ $1 == "db" || $1 == "res" ]]; then
if [[ $1 == "res" ]]; then
echo "Pulling resources... this might take a long time, because adb sucks..."
mkdir -p resource; cd resource
for d in image2 voice2 emoji video sfs; do
for d in avatar image2 voice2 emoji video sfs; do
mkdir -p $d; cd $d
adb pull "$RES_DIR/$chooseUser/$d"
cd ..
+21 -6
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: avatar.py
# Date: Thu Jun 18 00:02:07 2015 +0800
# Date: Wed Nov 29 01:33:56 2017 -0800
# Author: Yuxin Wu <[email protected]>
from PIL import Image
@@ -14,19 +14,27 @@ logger = logging.getLogger(__name__)
from common.textutil import ensure_bin_str, md5
class AvatarReader(object):
def __init__(self, avt_dir, avt_db="avatar.index"):
self.avt_dir = avt_dir
# new location of avatar, see #50
self.avt_dir_new = avt_dir[:avt_dir.find('sfs')] + 'avatar'
self.avt_db = avt_db
if self.avt_db is None or not os.path.isfile(self.avt_db):
self._use_avt = True
if self.avt_db is not None and os.path.isfile(self.avt_db):
self.ava_use_db = True
elif os.path.isdir(self.avt_dir_new):
self.ava_use_db = False
else:
logger.warn(
"Avatar database {} not found. Will not use avatar!".format(avt_db))
self.avt_db = None
self._use_avt = False
def get_avatar(self, username):
""" username: `username` field in db.rcontact"""
if self.avt_db is None:
if not self._use_avt:
return None
username = ensure_bin_str(username)
@@ -37,8 +45,15 @@ class AvatarReader(object):
try:
try:
pos, size = self.query_index(filename)
return self.read_img(pos, size)
if self.avt_use_db:
pos, size = self.query_index(filename)
return self.read_img(pos, size)
else:
img_file = os.path.join(self.avt_dir_new, filename)
if os.path.exists(img_file):
return Image.open(img_file)
else:
return None
except TypeError:
logger.warn("Avatar for {} not found in avatar database.".format(username))
return None
+4
View File
@@ -95,6 +95,10 @@ class HTMLRender(object):
sender = u'you ' + msg.talker if not msg.isSend else 'me'
format_dict = {'sender_label': sender,
'time': msg.createTime }
if(not msg.isSend and msg.is_chatroom()):
format_dict['nickname'] = '>\n <pre align=\'left\'>'+msg.talker_nickname+'</pre'
else:
format_dict['nickname'] = ' '
def fallback():
template = TEMPLATES[TYPE_MSG]
content = msg.msg_str()
+1 -1
View File
@@ -2,7 +2,7 @@
<div class="chatItemContent">
<span class="avatar"></span>
<div class="cloud cloudImg">
<div class="cloudPannel" title="{time}">
<div class="cloudPannel" title="{time}" {nickname}>
<div class="cloudBody">
<div class="cloudContent">
<span class="img_wrap">
+1 -1
View File
@@ -2,7 +2,7 @@
<div class="chatItemContent">
<span class="avatar"></span>
<div class="cloud cloudImg">
<div class="cloudPannel" title="{time}">
<div class="cloudPannel" title="{time}" {nickname}>
<div class="cloudBody">
<div class="cloudContent">
<span class="img_wrap">
+1 -1
View File
@@ -2,7 +2,7 @@
<div class="chatItemContent">
<span class="avatar"></span>
<div class="cloud cloudText">
<div class="cloudPannel" title="{time}">
<div class="cloudPannel" title="{time}" {nickname}>
<div class="cloudBody">
<div class="cloudContent">
<pre style="white-space:pre-wrap">{content}</pre>
+1 -1
View File
@@ -2,7 +2,7 @@
<div class="chatItemContent">
<span class="avatar"></span>
<div class="cloud cloudVoice" onclick="playVoice(event)" style="width:80px">
<div class="cloudPannel" title="{time}">
<div class="cloudPannel" title="{time}" {nickname}>
<div class="sendStatus">
<span class="second">{voice_duration}"</span>
</div>