feat: (localMusic) 优化读取本地音乐meta信息,修复重复读取的问题

This commit is contained in:
helloplhm-qwq
2024-02-04 16:27:36 +08:00
parent 35f1fe513a
commit b9a1e530dd
2 changed files with 21 additions and 7 deletions

View File

@ -7,6 +7,7 @@
# ----------------------------------------
# This file is part of the "lx-music-api-server" project.
import hashlib
import platform
import binascii
import builtins
@ -16,7 +17,6 @@ import time
import re
import xmltodict
from urllib.parse import quote, unquote, urlparse
from hashlib import md5 as handleCreateMD5
def createBase64Encode(data_bytes):
encoded_data = base64.b64encode(data_bytes)
@ -67,7 +67,14 @@ def filterFileName(filename):
def createMD5(s: (str, bytes)):
if (isinstance(s, str)):
s = s.encode("utf-8")
return handleCreateMD5(s).hexdigest()
return hashlib.md5(s).hexdigest()
def createFileMD5(path):
with open(path, 'rb') as f:
md5 = hashlib.md5()
for chunk in iter(lambda: f.read(4096), b""):
md5.update(chunk)
return md5.hexdigest()
def readFile(path, mode = "text"):
try: