use empty avatar in failure

This commit is contained in:
Yuxin Wu
2016-01-08 21:38:21 -05:00
parent 0d8136bed5
commit 32312072ab
6 changed files with 24 additions and 16 deletions
+3
View File
@@ -9,6 +9,9 @@ It can generate single-file html containing all the messages, including voice me
__NEWS__: WeChat 6.0+ use silk to encode audio. The code is updated.
The latest version of WeChat uses a new avatar storage. Currently I don't have time investigating that. You're expected to
see generated htmls without avatars. Contributions welcomed!
### How to use:
#### Dependencies:
+4 -4
View File
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/bin/bash
# File: android-interact.sh
# Date: Fri Jun 26 10:38:07 2015 +0800
# Author: Yuxin Wu <[email protected]>
@@ -18,7 +18,7 @@ adb root
if [[ $1 == "uin" ]]; then
adb pull $MM_DIR/shared_prefs/system_config_prefs.xml 2>/dev/null
uin=$($GREP 'default_uin' system_config_prefs.xml | $GREP -o 'value="-\?[0-9]*' | cut -c 8-)
uin=$($GREP 'default_uin' system_config_prefs.xml | $GREP -o 'value="\-?[0-9]*' | cut -c 8-)
[[ -n $uin ]] || {
>&2 echo "Failed to get wechat uin. You can try other methods, or report a bug."
exit 1
@@ -26,7 +26,7 @@ if [[ $1 == "uin" ]]; then
rm system_config_prefs.xml
echo "Got wechat uin: $uin"
elif [[ $1 == "imei" ]]; then
imei=$(adb shell dumpsys iphonesubinfo | $GREP 'Device ID' | $GREP -o '[0-9]\+')
imei=$(adb shell dumpsys iphonesubinfo | $GREP 'Device ID' | $GREP -o '[0-9]+')
[[ -n $imei ]] || {
>&2 echo "Failed to get imei. You can try other methods, or report a bug."
exit 1
@@ -78,7 +78,7 @@ elif [[ $1 == "db" || $1 == "res" ]]; then
fi
elif [[ $1 == "db-decrypt" ]]; then
echo "Getting uin..."
$0 uin | tail -n1 | $GREP -o '-\?[0-9]*' | tee /tmp/uin
$0 uin | tail -n1 | $GREP -o '\-?[0-9]*' | tee /tmp/uin
echo "Getting imei..."
$0 imei | tail -n1 | $GREP -o '[0-9]*' | tee /tmp/imei
echo "Getting db..."
+1 -1
View File
@@ -13,7 +13,7 @@ if [ `uname` = 'Darwin' ]; then
MD5SUM='md5'
else
REALPATH='readlink -f'
GREP=grep
GREP='grep -E'
MD5SUM='md5sum'
fi
+14 -9
View File
@@ -25,16 +25,21 @@ class AvatarReader(object):
filename = os.path.join(dir1, dir2,
"user_{}.png.bm".format(filename))
index_avatar = self.query_index(filename)
if index_avatar == -1:
logger.warn("Avatar not found for {}".format(username))
try:
index_avatar = self.query_index(filename)
if index_avatar == -1:
logger.warn("Avatar not found for {}".format(username))
return None
else:
img = self.read_bm_block(index_avatar)
return img
except:
logger.warn("Failed to retrieve avatar!")
return None
else:
img = self.read_bm_block(index_avatar)
return img
def read_bm_block(self, pos):
file_idx = pos >> 32
file_idx = pos >> 32
fname = os.path.join(self.avt_dir,
'avatar.block.' + '{:05d}'.format(file_idx))
# 16 is unknown prefix
@@ -45,8 +50,8 @@ class AvatarReader(object):
f.seek(start_pos)
size = (96, 96, 3)
img = np.zeros(size, dtype='uint8')
for i in range(96):
for j in range(96):
for i in xrange(96):
for j in xrange(96):
r, g, b, a = map(ord, f.read(4))
img[i,j] = (r, g, b)
return img
+1 -1
View File
@@ -19,7 +19,7 @@ class LibChatHelper(object):
""" Build LibChat messages from WeChat Msg"""
""" Types of message whose contents are fully parsed.
No need to save extra data for them. """
No need to save extra data for them. """
FullyParsed = [TYPE_MSG, TYPE_SPEAK, TYPE_EMOJI,
TYPE_CUSTOM_EMOJI, TYPE_IMG]
+1 -1
View File
@@ -67,7 +67,7 @@ class WeChatMsg(object):
pass
return "LOCATION:" + label + " ({},{})".format(loc['x'], loc['y'])
elif self.type == TYPE_LINK:
pq = PyQuery(self.content_xml_ready, parser='xml')
pq = PyQuery(self.content_xml_ready)
url = pq('url').text()
if not url:
title = pq('title').text()