diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py
index 037c5eb..b0ff151 100644
--- a/app/DataBase/msg.py
+++ b/app/DataBase/msg.py
@@ -57,6 +57,21 @@ class Msg:
lock.release()
def get_messages(self, username_):
+ '''
+ return list
+ a[0]: localId,
+ a[1]: talkerId, (和strtalker对应的,不是群聊信息发送人)
+ a[2]: type,
+ a[3]: subType,
+ a[4]: is_sender,
+ a[5]: timestamp,
+ a[6]: status, (没啥用)
+ a[7]: str_content,
+ a[8]: str_time, (格式化的时间)
+ a[9]: msgSvrId,
+ a[10]: BytesExtra,
+ a[11]: CompressContent,
+ '''
if not self.open_flag:
return None
sql = '''
diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py
index aa6e479..0330610 100644
--- a/app/DataBase/output_pc.py
+++ b/app/DataBase/output_pc.py
@@ -4,6 +4,7 @@ import os
from re import findall
from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5.QtWidgets import QFileDialog
+from eyed3 import load
from . import msg_db, micro_msg_db
from .package_msg import PackageMsg
@@ -26,6 +27,7 @@ def makedirs(path):
os.makedirs(os.path.join(path, 'video'), exist_ok=True)
os.makedirs(os.path.join(path, 'voice'), exist_ok=True)
os.makedirs(os.path.join(path, 'file'), exist_ok=True)
+ os.makedirs(os.path.join(path, 'avatar'), exist_ok=True)
def escape_js_and_html(input_str):
@@ -136,6 +138,18 @@ class Output(QThread):
self.requestInterruption()
+def modify_audio_metadata(audiofile, new_artist): # 修改音频元数据中的“创作者”标签
+ audiofile = load(audiofile)
+
+ # 检查文件是否有标签
+ if audiofile.tag is None:
+ audiofile.initTag()
+
+ # 修改艺术家名称
+ audiofile.tag.artist = new_artist
+ audiofile.tag.save()
+
+
class ChildThread(QThread):
"""
子线程,用于导出部分聊天记录
@@ -168,20 +182,32 @@ class ChildThread(QThread):
str_content = message[7]
str_time = message[8]
is_send = message[4]
- avatar = 'myhead.png' if is_send else 'tahead.png'
timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
+ if is_chatroom:
+ avatar = f"./avatar/{message[12].wxid}.png"
+ else:
+ avatar = f"./avatar/{MePC().wxid if is_send else self.contact.wxid}.png"
+ if is_chatroom:
+ if is_send:
+ displayname = MePC().name
+ else:
+ displayname = message[12].remark
+ else:
+ displayname = MePC().name if is_send else self.contact.remark
+ displayname = escape_js_and_html(displayname)
if self.output_type == Output.HTML:
str_content = escape_js_and_html(str_content)
if self.is_5_min(timestamp):
doc.write(
- f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:''}},'''
+ f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
emojiText = findall(r"(\[.+?\])", str_content)
for emoji_text in emojiText:
if emoji_text in emoji:
str_content = str_content.replace(emoji_text, emoji[emoji_text])
doc.write(
- f'''{{ type:{1}, text: '{str_content}',is_send:{is_send},avatar_path:'{avatar}'}},'''
+ f'''{{ type:{1}, text: '{str_content}',is_send:{is_send},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
elif self.output_type == Output.TXT:
name = '你' if is_send else self.contact.remark
@@ -195,9 +221,21 @@ class ChildThread(QThread):
str_content = message[7]
str_time = message[8]
is_send = message[4]
- avatar = 'myhead.png' if is_send else 'tahead.png'
- timestamp = message[5]
BytesExtra = message[10]
+ timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
+ if is_chatroom:
+ avatar = f"./avatar/{message[12].wxid}.png"
+ else:
+ avatar = f"./avatar/{MePC().wxid if is_send else self.contact.wxid}.png"
+ if is_chatroom:
+ if is_send:
+ displayname = MePC().name
+ else:
+ displayname = message[12].remark
+ else:
+ displayname = MePC().name if is_send else self.contact.remark
+ displayname = escape_js_and_html(displayname)
if self.output_type == Output.HTML:
str_content = escape_js_and_html(str_content)
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
@@ -218,10 +256,10 @@ class ChildThread(QThread):
# print(f"tohtml:---{image_path}")
if self.is_5_min(timestamp):
doc.write(
- f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:''}},'''
+ f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
doc.write(
- f'''{{ type:{type_}, text: '{image_path}',is_send:{is_send},avatar_path:'{avatar}'}},'''
+ f'''{{ type:{type_}, text: '{image_path}',is_send:{is_send},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
elif self.output_type == Output.TXT:
name = '你' if is_send else self.contact.remark
@@ -234,24 +272,37 @@ class ChildThread(QThread):
str_content = message[7]
str_time = message[8]
is_send = message[4]
- avatar = 'myhead.png' if is_send else 'tahead.png'
- timestamp = message[5]
msgSvrId = message[9]
+ timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
+ if is_chatroom:
+ avatar = f"./avatar/{message[12].wxid}.png"
+ else:
+ avatar = f"./avatar/{MePC().wxid if is_send else self.contact.wxid}.png"
+ if is_chatroom:
+ if is_send:
+ displayname = MePC().name
+ else:
+ displayname = message[12].remark
+ else:
+ displayname = MePC().name if is_send else self.contact.remark
+ displayname = escape_js_and_html(displayname)
if self.output_type == Output.HTML:
try:
audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice")
audio_path = audio_path.replace('/', '\\')
+ modify_audio_metadata(audio_path, displayname)
os.utime(audio_path, (timestamp, timestamp))
audio_path = audio_path.replace('\\', '/')
- voice_to_text = media_msg_db.get_audio_text(str_content)
+ voice_to_text = escape_js_and_html(media_msg_db.get_audio_text(str_content))
except:
return
if self.is_5_min(timestamp):
doc.write(
- f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:''}},'''
+ f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
doc.write(
- f'''{{ type:34, text:'{audio_path}',is_send:{is_send},avatar_path:'{avatar}',voice_to_text:'{voice_to_text}'}},'''
+ f'''{{ type:34, text:'{audio_path}',is_send:{is_send},avatar_path:'{avatar}',voice_to_text:'{voice_to_text}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
if self.output_type == Output.TXT:
name = '你' if is_send else self.contact.remark
@@ -264,17 +315,33 @@ class ChildThread(QThread):
str_content = message[7]
str_time = message[8]
is_send = message[4]
- avatar = 'myhead.png' if is_send else 'tahead.png'
timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
+ if is_chatroom:
+ avatar = f"./avatar/{message[12].wxid}.png"
+ else:
+ avatar = f"./avatar/{MePC().wxid if is_send else self.contact.wxid}.png"
+ if is_chatroom:
+ if is_send:
+ displayname = MePC().name
+ else:
+ displayname = message[12].remark
+ else:
+ displayname = MePC().name if is_send else self.contact.remark
+ displayname = escape_js_and_html(displayname)
if self.output_type == Output.HTML:
emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
- emoji_path = './emoji/' + os.path.basename(emoji_path)
+ if emoji_path == "":
+ shutil.copy(f"{os.path.abspath('.')}/app/resources/icons/404.png", origin_docx_path + '/emoji/404.png')
+ emoji_path = "./emoji/404.png"
+ else:
+ emoji_path = './emoji/' + os.path.basename(emoji_path)
if self.is_5_min(timestamp):
doc.write(
- f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:''}},'''
+ f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
doc.write(
- f'''{{ type:{3}, text: '{emoji_path}',is_send:{is_send},avatar_path:'{avatar}'}},'''
+ f'''{{ type:{3}, text: '{emoji_path}',is_send:{is_send},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
elif self.output_type == Output.TXT:
name = '你' if is_send else self.contact.remark
@@ -302,6 +369,20 @@ class ChildThread(QThread):
avatar = 'myhead.png' if is_send else 'tahead.png'
content = parser_reply(message[11])
refer_msg = content.get('refer')
+ timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
+ if is_chatroom:
+ avatar = f"./avatar/{message[12].wxid}.png"
+ else:
+ avatar = f"./avatar/{MePC().wxid if is_send else self.contact.wxid}.png"
+ if is_chatroom:
+ if is_send:
+ displayname = MePC().name
+ else:
+ displayname = message[12].remark
+ else:
+ displayname = MePC().name if is_send else self.contact.remark
+ displayname = escape_js_and_html(displayname)
if self.output_type == Output.HTML:
contentText = content.get('title')
emojiText = findall(r"(\[.+?\])", contentText)
@@ -315,11 +396,11 @@ class ChildThread(QThread):
if emoji_text in emoji:
referText = referText.replace(emoji_text, emoji[emoji_text])
doc.write(
- f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},refer_text: '{referText}',avatar_path:'{avatar}'}},'''
+ f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},refer_text: '{referText}',avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
else:
doc.write(
- f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},avatar_path:'{avatar}'}},'''
+ f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
elif self.output_type == Output.TXT:
name = '你' if is_send else self.contact.remark
@@ -336,10 +417,12 @@ class ChildThread(QThread):
str_content = message[7]
is_send = message[4]
str_time = message[8]
+ timestamp = message[5]
+ is_chatroom = 1 if self.contact.is_chatroom else 0
str_content = escape_js_and_html(str_content.lstrip('