forked from ppwwyyxx/wechat-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump-audio.py
executable file
·49 lines (41 loc) · 1.54 KB
/
dump-audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# File: dump-audio.py
# Author: Yuxin Wu
import sys
import argparse
from common.textutil import ensure_unicode
from wechat.parser import WeChatDBParser
from wechat.res import Resource
from wechat.render import HTMLRender
from wechat.libchathelper import LibChatHelper
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('name', help='name of contact')
parser.add_argument('--output', help='output mp3 dir', default='/tmp')
parser.add_argument('--db', default='decrypted.db', help='path to decrypted database')
parser.add_argument('--res', default='resource', help='reseource directory')
args = parser.parse_args()
return args
if __name__ == '__main__':
args = get_args()
name = ensure_unicode(args.name)
output_file = args.output
parser = WeChatDBParser(args.db)
res = Resource(parser, args.res, '')
if name and name in parser.msgs_by_chat:
msgs = parser.msgs_by_chat[name]
else:
sys.stderr.write(u"Valid Contacts: {}\n".format(u'\n'.join(parser.msgs_by_chat.keys())))
sys.stderr.write(u"Couldn't find that contact {}.".format(name));
sys.exit(1)
print "Number of Messages: ", len(msgs)
assert len(msgs) > 0
libchat = LibChatHelper(parser, res)
msgs = libchat.convert_msgs(msgs)
voices = [m.sound for m in msgs if m.sound]
for idx, v in enumerate(voices):
p = v.find(':')
v = v[p:]
with open('/{}/{:04d}.mp3'.format(args.output, idx), 'wb') as f:
f.write(v)