给音频的元数据加上创作者信息,便于本地归类查找

This commit is contained in:
STDquantum 2023-12-15 14:48:54 +08:00
parent 24a99ff00d
commit 4815b31967
2 changed files with 17 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import os
from re import findall from re import findall
from PyQt5.QtCore import pyqtSignal, QThread 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
@ -136,6 +137,18 @@ class Output(QThread):
self.requestInterruption() 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): class ChildThread(QThread):
""" """
子线程用于导出部分聊天记录 子线程用于导出部分聊天记录
@ -235,12 +248,14 @@ class ChildThread(QThread):
str_time = message[8] str_time = message[8]
is_send = message[4] is_send = message[4]
avatar = 'myhead.png' if is_send else 'tahead.png' avatar = 'myhead.png' if is_send else 'tahead.png'
creatorName = MePC().name if is_send else self.contact.remark
timestamp = message[5] timestamp = message[5]
msgSvrId = message[9] msgSvrId = message[9]
if self.output_type == Output.HTML: if self.output_type == Output.HTML:
try: try:
audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice") audio_path = media_msg_db.get_audio(msgSvrId, output_path=origin_docx_path + "/voice")
audio_path = audio_path.replace('/', '\\') audio_path = audio_path.replace('/', '\\')
modify_audio_metadata(audio_path, creatorName)
os.utime(audio_path, (timestamp, timestamp)) os.utime(audio_path, (timestamp, timestamp))
audio_path = audio_path.replace('\\', '/') audio_path = audio_path.replace('\\', '/')
voice_to_text = media_msg_db.get_audio_text(str_content) voice_to_text = media_msg_db.get_audio_text(str_content)

View File

@ -16,4 +16,5 @@ google==3.0.0
protobuf==4.25.1 protobuf==4.25.1
soupsieve==2.5 soupsieve==2.5
lz4==4.3.2 lz4==4.3.2
pilk==0.2.4 pilk==0.2.4
eyed3==0.9.7