修改文件位置

This commit is contained in:
shuaikangzhou 2023-12-23 15:25:02 +08:00
parent b1a6f52148
commit 5916e55c1b
6 changed files with 4780 additions and 6618 deletions

View File

@ -80,20 +80,22 @@ class MediaMsg:
try: try:
# 调用系统上的 ffmpeg 可执行文件 # 调用系统上的 ffmpeg 可执行文件
# 获取 FFmpeg 可执行文件的路径 # 获取 FFmpeg 可执行文件的路径
# ffmpeg_path = get_ffmpeg_path() ffmpeg_path = get_ffmpeg_path()
# # 调用 FFmpeg # # 调用 FFmpeg
# cmd = f'''{ffmpeg_path} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}''' if os.path.exists(ffmpeg_path):
# system(cmd) cmd = f'''{ffmpeg_path} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}'''
# 源码运行的时候下面的有效 system(cmd)
# 这里不知道怎么捕捉异常 else:
cmd = f'''{os.path.join(os.getcwd(), 'app', 'resources', 'ffmpeg.exe')} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}''' # 源码运行的时候下面的有效
system(cmd) # 这里不知道怎么捕捉异常
cmd = f'''{os.path.join(os.getcwd(), 'app', 'resources', 'ffmpeg.exe')} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}'''
system(cmd)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f"Error: {e}") print(f"Error: {e}")
cmd = f'''{os.path.join(os.getcwd(),'app','resources','ffmpeg.exe')} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}''' cmd = f'''{os.path.join(os.getcwd(),'app','resources','ffmpeg.exe')} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}'''
system(cmd) system(cmd)
# system(f'del {silk_path}') system(f'del {silk_path}')
# system(f'del {pcm_path}') system(f'del {pcm_path}')
print(mp3_path) print(mp3_path)
return mp3_path return mp3_path
def get_audio_path(self, reserved0, output_path): def get_audio_path(self, reserved0, output_path):

View File

@ -1,19 +1,20 @@
import csv import csv
import html import html
import os import os
import sys
import traceback
from re import findall from re import findall
from PyQt5.QtCore import pyqtSignal, QThread, QFile, QIODevice, QTextStream from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5.QtWidgets import QFileDialog from PyQt5.QtWidgets import QFileDialog
# from eyed3 import load
from . import msg_db, micro_msg_db from . import msg_db, micro_msg_db
from .package_msg import PackageMsg from .package_msg import PackageMsg
from ..DataBase import hard_link_db from ..DataBase import hard_link_db
from ..DataBase import media_msg_db from ..DataBase import media_msg_db
from ..log import logger
from ..person import MePC from ..person import MePC
from ..util import path from ..util import path
import shutil import shutil
from ..util.compress_content import parser_reply 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
@ -506,12 +507,12 @@ class ChildThread(QThread):
else: else:
messages = msg_db.get_messages(self.contact.wxid) messages = msg_db.get_messages(self.contact.wxid)
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html" filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html"
file = QFile(':/data/template.html') file_path = './app/resources/template.html'
if file.open(QIODevice.ReadOnly | QIODevice.Text): if not os.path.exists(file_path):
stream = QTextStream(file) resource_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
stream.setCodec('utf-8') file_path = os.path.join(resource_dir, 'app', 'resources', 'template.html')
content = stream.readAll() with open(file_path, "r", encoding="utf-8") as f:
file.close() content = f.read()
html_head, html_end = content.split('/*注意看这是分割线*/') html_head, html_end = content.split('/*注意看这是分割线*/')
f = open(filename, 'w', encoding='utf-8') f = open(filename, 'w', encoding='utf-8')
f.write(html_head.replace("<title>Chat Records</title>", f"<title>{self.contact.remark}</title>")) f.write(html_head.replace("<title>Chat Records</title>", f"<title>{self.contact.remark}</title>"))
@ -616,17 +617,20 @@ class OutputMedia(QThread):
for message in messages: for message in messages:
is_send = message[4] is_send = message[4]
msgSvrId = message[9] msgSvrId = message[9]
audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice") try:
audio_path = audio_path.replace('/', '\\') audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice")
if self.contact.is_chatroom: audio_path = audio_path.replace('/', '\\')
if is_send: if self.contact.is_chatroom:
displayname = MePC().name if is_send:
displayname = MePC().name
else:
displayname = message[12].remark
else: else:
displayname = message[12].remark displayname = MePC().name if is_send else self.contact.remark
else: displayname = escape_js_and_html(displayname)
displayname = MePC().name if is_send else self.contact.remark modify_audio_metadata(audio_path, displayname)
displayname = escape_js_and_html(displayname) except:
modify_audio_metadata(audio_path, displayname) logger.error(traceback.format_exc())
# os.utime(audio_path, (timestamp, timestamp)) # os.utime(audio_path, (timestamp, timestamp))
self.progressSignal.emit(1) self.progressSignal.emit(1)
self.okSingal.emit(34) self.okSingal.emit(34)
@ -645,6 +649,9 @@ class OutputEmoji(QThread):
messages = msg_db.get_messages_by_type(self.contact.wxid, 47) messages = msg_db.get_messages_by_type(self.contact.wxid, 47)
for message in messages: for message in messages:
str_content = message[7] str_content = message[7]
emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji') try:
emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
except:
logger.error(traceback.format_exc())
self.progressSignal.emit(1) self.progressSignal.emit(1)
self.okSingal.emit(34) self.okSingal.emit(34)

View File

@ -1,3 +1,4 @@
import os
from collections import Counter from collections import Counter
from PyQt5.QtCore import QFile, QTextStream, QIODevice from PyQt5.QtCore import QFile, QTextStream, QIODevice
@ -93,17 +94,17 @@ def wordcloud_christmas(wxid, year='2023'):
stopwords_file = './app/data/stopwords.txt' stopwords_file = './app/data/stopwords.txt'
with open(stopwords_file, "r", encoding="utf-8") as stopword_file: with open(stopwords_file, "r", encoding="utf-8") as stopword_file:
stopwords1 = set(stopword_file.read().splitlines()) stopwords1 = set(stopword_file.read().splitlines())
file = QFile(':/data/stopwords.txt') # 构建 FFmpeg 可执行文件的路径
stopwords = set() stopwords = set()
if file.open(QIODevice.ReadOnly | QIODevice.Text): stopwords_file = './app/resources/stopwords.txt'
stream = QTextStream(file) if not os.path.exists(stopwords_file):
stream.setCodec('utf-8') resource_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
content = stream.readAll() stopwords_file = os.path.join(resource_dir, 'app', 'resources', 'stopwords.txt')
file.close() with open(stopwords_file, "r", encoding="utf-8") as stopword_file:
stopwords = set(content.splitlines()) stopwords = set(stopword_file.read().splitlines())
stopwords = stopwords.union(stopwords1) stopwords = stopwords.union(stopwords1)
filtered_word_count = {word: count for word, count in word_count.items() if len(word) > 1 and word not in stopwords}
filtered_word_count = {word: count for word, count in word_count.items() if len(word) > 1 and word not in stopwords}
# 转换为词云数据格式 # 转换为词云数据格式
data = [(word, count) for word, count in filtered_word_count.items()] data = [(word, count) for word, count in filtered_word_count.items()]
# text_data = data # text_data = data

View File

@ -30,8 +30,6 @@
<file>icons/decrypt.svg</file> <file>icons/decrypt.svg</file>
</qresource> </qresource>
<qresource prefix="/data"> <qresource prefix="/data">
<file>version_list.json</file>
<file>stopwords.txt</file>
<file>template.html</file>
</qresource> </qresource>
</RCC> </RCC>

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
import json import json
import os.path import os.path
import sys
import time import time
import traceback import traceback
@ -49,14 +50,12 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog):
# @log # @log
def get_info(self): def get_info(self):
try: try:
file = QFile(':/data/version_list.json') file_path = './app/resources/version_list.json'
if file.open(QIODevice.ReadOnly | QIODevice.Text): if not os.path.exists(file_path):
stream = QTextStream(file) resource_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
content = stream.readAll() file_path = os.path.join(resource_dir, 'app', 'resources', 'version_list.json')
file.close() with open(file_path, "r", encoding="utf-8") as f:
VERSION_LIST = json.loads(content) VERSION_LIST = json.loads(f.read())
else:
return
result = get_wx_info.get_info(VERSION_LIST) result = get_wx_info.get_info(VERSION_LIST)
print(result) print(result)
if result == -1: if result == -1: