Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

把emoji变成url #225

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions app/DataBase/output_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..util import path
import shutil
from ..util.compress_content import parser_reply
from ..util.emoji import get_emoji, get_emoji_path
from ..util.emoji import get_emoji, get_emoji_path, get_emoji_url
from ..util.image import get_image_path, get_image

os.makedirs('./data/聊天记录', exist_ok=True)
Expand Down Expand Up @@ -345,8 +345,9 @@ def emoji(self, doc, message):
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_path(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
emoji_path = './emoji/' + os.path.basename(emoji_path)
# emoji_path = get_emoji_path(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
# emoji_path = './emoji/' + os.path.basename(emoji_path)
emoji_path = get_emoji_url(str_content, thumb=True)
doc.write(
f'''{{ type:{3}, text: '{emoji_path}',is_send:{is_send},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
)
Expand Down Expand Up @@ -750,3 +751,28 @@ def run(self):
self.progressSignal.emit(1)
self.okSingal.emit(47)
print('图片子线程完成')


if __name__ == "__main__":
from app.DataBase import micro_msg_db, misc_db
from app.person import ContactPC
from PyQt5.QtGui import QGuiApplication
app = QGuiApplication([])
contact_info_list = micro_msg_db.get_contact_by_username("wxid_lhbdvh3cnn4h22")
contact_info = {
'UserName': contact_info_list[0],
'Alias': contact_info_list[1],
'Type': contact_info_list[2],
'Remark': contact_info_list[3],
'NickName': contact_info_list[4],
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
mess = {1: True, 3: True, 34: True, 43: True, 47: True, 10000: True}
MePC().name = "无题"
MePC().wx_dir = r"C:\Users\HUAWEI\Documents\WeChat Files\wxid_05rvkbftizq822"
MePC().wxid = "wxid_05rvkbftizq822"
ChildThread(contact, 2, mess).to_html_()
app.quit()
45 changes: 44 additions & 1 deletion app/util/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def init_database(self):
if lock.locked():
lock.release()

def get_emoji_url(self, md5: str, thumb: bool):
def get_emoji_url(self, md5: str, thumb: bool) -> str | bytes:
'''供下载用,返回可能是url可能是bytes'''
if thumb:
sql = '''
select
Expand Down Expand Up @@ -129,6 +130,33 @@ def get_emoji_url(self, md5: str, thumb: bool):
finally:
lock.release()

def get_emoji_URL(self, md5: str, thumb: bool):
'''只管url,另外的不管'''
if thumb:
sql = '''
select
case
when thumburl is NULL or thumburl = '' then cdnurl
else thumburl
end as selected_url
from CustomEmotion
where md5 = ?
'''
else:
sql = '''
select CDNUrl
from CustomEmotion
where md5 = ?
'''
try:
lock.acquire(True)
self.cursor.execute(sql, [md5])
return self.cursor.fetchone()[0]
except:
return ""
finally:
lock.release()

def close(self):
if self.open_flag:
try:
Expand Down Expand Up @@ -187,6 +215,7 @@ def get_most_emoji(messages):


def get_emoji(xml_string, thumb=True, output_path=root_path) -> str:
"""供下载用"""
try:
emoji_info = parser_xml(xml_string)
md5 = emoji_info['md5']
Expand Down Expand Up @@ -243,6 +272,20 @@ def get_emoji_path(xml_string, thumb=True, output_path=root_path) -> str:
logger.error(traceback.format_exc())
output_path = os.path.join(output_path, "404.png")
return output_path

def get_emoji_url(xml_string, thumb=True) -> str:
"""不管下载,只返回url"""
try:
emoji_info = parser_xml(xml_string)
md5 = emoji_info['md5']
url = emoji_info["thumburl" if thumb else "cdnurl"]
if not url or url == '':
url = Emotion().get_emoji_URL(md5=md5, thumb=thumb)
return url
except:
logger.error(traceback.format_exc())
output_path = os.path.join(output_path, "404.png")
return output_path


if __name__ == '__main__':
Expand Down