Skip to content

Commit

Permalink
- append MsgId after fileName for pic, audio and video in case of ove…
Browse files Browse the repository at this point in the history
…rwritten

- change default pic extention to jpg which most of the pics were
- use html.unescape, meaning requiring python 3.4+
- change empty content msg of type 51(ue init) to useless by default,
    user probably checking history messages on phone
  • Loading branch information
eshiyho committed Apr 25, 2019
1 parent d5ce5db commit ea0704f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions itchat/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def produce_msg(core, msgList):
'%s/webwxgetmsgimg' % core.loginInfo['url'], m['NewMsgId'])
msg = {
'Type' : 'Picture',
'FileName' : '%s.%s' % (time.strftime('%y%m%d-%H%M%S', time.localtime()),
'png' if m['MsgType'] == 3 else 'gif'),
'FileName' : '%s_%s.%s' % (time.strftime('%y%m%d-%H%M%S', time.localtime()), m['MsgId'],
'jpg' if m['MsgType'] == 3 else 'gif'),
'Text' : download_fn, }
elif m['MsgType'] == 34: # voice
download_fn = get_download_fn(core,
'%s/webwxgetvoice' % core.loginInfo['url'], m['NewMsgId'])
msg = {
'Type': 'Recording',
'FileName' : '%s.mp3' % time.strftime('%y%m%d-%H%M%S', time.localtime()),
'FileName' : '%s_%s.mp3' % (time.strftime('%y%m%d-%H%M%S', time.localtime()), m['MsgId']),
'Text': download_fn,}
elif m['MsgType'] == 37: # friends
m['User']['UserName'] = m['RecommendInfo']['UserName']
Expand Down Expand Up @@ -138,7 +138,7 @@ def download_video(videoDir=None):
'Ret': 0, }})
msg = {
'Type': 'Video',
'FileName' : '%s.mp4' % time.strftime('%y%m%d-%H%M%S', time.localtime()),
'FileName' : '%s_%s.mp4' % (time.strftime('%y%m%d-%H%M%S', time.localtime()), m['MsgId']),
'Text': download_video, }
elif m['MsgType'] == 49: # sharing
if m['AppMsgType'] == 0: # chat history
Expand Down Expand Up @@ -198,7 +198,7 @@ def download_atta(attaDir=None):
msg = {
'Type': 'Sharing',
'Text': m['FileName'], }
elif m['MsgType'] == 51: # phone init
elif m['MsgType'] == 51 and m['Content']: # phone init
msg = update_local_uin(core, m)
elif m['MsgType'] == 10000:
msg = {
Expand Down
3 changes: 2 additions & 1 deletion itchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from urllib.parse import quote

import requests
import html

from . import config

Expand Down Expand Up @@ -71,7 +72,7 @@ def _emoji_formatter(m):
def msg_formatter(d, k):
emoji_formatter(d, k)
d[k] = d[k].replace('<br/>', '\n')
d[k] = htmlParser.unescape(d[k])
d[k] = html.unescape(d[k])

def check_file(fileDir):
try:
Expand Down

0 comments on commit ea0704f

Please sign in to comment.