feature:支持wma格式

This commit is contained in:
charlesxie
2023-09-06 17:12:25 +08:00
parent 7016c58b3d
commit 4e36df26fd
6 changed files with 52 additions and 30 deletions

View File

@@ -10,6 +10,7 @@
venv
.git
/web/
/build/
/media/
db.sqlite3
local_settings.py

1
.gitignore vendored
View File

@@ -19,3 +19,4 @@ yarn-error.log*
local_settings.py
db.sqlite3
/media/
/build/

View File

@@ -566,7 +566,7 @@ class AudioFile(object):
if not remover:
if isinstance(tmap.setter, (list, tuple)):
remover = [s for s in tmap.setter if isinstance(g, util.string_types)]
remover = [s for s in tmap.setter if isinstance(s, util.string_types)]
if isinstance(tmap.setter, util.string_types):
remover = [tmap.setter]

View File

@@ -11,12 +11,6 @@ import ctypes.util
if sys.version_info[0] >= 3:
BUFFER_TYPES = (memoryview, bytearray,)
BYTES_TYPE = bytes
elif sys.version_info[1] >= 7:
BUFFER_TYPES = (buffer, memoryview, bytearray,) # noqa: F821
BYTES_TYPE = str
else:
BUFFER_TYPES = (buffer, bytearray,) # noqa: F821
BYTES_TYPE = str
# Find the base library and declare prototypes.
@@ -56,7 +50,6 @@ for name in _guess_lib_name():
else:
raise ImportError("couldn't find libchromaprint")
_libchromaprint.chromaprint_get_version.argtypes = ()
_libchromaprint.chromaprint_get_version.restype = ctypes.c_char_p
@@ -117,7 +110,6 @@ def _check(res):
class Fingerprinter(object):
ALGORITHM_TEST1 = 0
ALGORITHM_TEST2 = 1
ALGORITHM_TEST3 = 2

View File

@@ -25,6 +25,7 @@ import argparse
import sys
import acoustid
# Copyright (C) 2011 Lukas Lalinsky
# (Minor modifications by Adrian Sampson.)
# Distributed under the MIT license, see the LICENSE file for details.
@@ -38,12 +39,6 @@ import ctypes.util
if sys.version_info[0] >= 3:
BUFFER_TYPES = (memoryview, bytearray,)
BYTES_TYPE = bytes
elif sys.version_info[1] >= 7:
BUFFER_TYPES = (buffer, memoryview, bytearray,) # noqa: F821
BYTES_TYPE = str
else:
BUFFER_TYPES = (buffer, bytearray,) # noqa: F821
BYTES_TYPE = str
# Find the base library and declare prototypes.
@@ -83,7 +78,6 @@ for name in _guess_lib_name():
else:
raise ImportError("couldn't find libchromaprint")
_libchromaprint.chromaprint_get_version.argtypes = ()
_libchromaprint.chromaprint_get_version.restype = ctypes.c_char_p
@@ -144,7 +138,6 @@ def _check(res):
class Fingerprinter(object):
ALGORITHM_TEST1 = 0
ALGORITHM_TEST2 = 1
ALGORITHM_TEST3 = 2
@@ -313,6 +306,3 @@ def main():
print('FILE=%s' % path)
print('DURATION=%d' % duration)
print('FINGERPRINT=%s' % fp.decode('utf8'))

View File

@@ -1,5 +1,6 @@
import re
from distutils.core import setup
import multiprocessing
from Cython.Build import cythonize
import os
@@ -8,11 +9,13 @@ import tempfile
import logging
import sys
NB_COMPILE_JOBS = multiprocessing.cpu_count()
# set up logging
logger = logging.getLogger("encrypt-py")
format_string = (
"%(asctime)s|%(filename)s|%(funcName)s|line:%(lineno)d|%(levelname)s| %(message)s"
"%(asctime)s|%(levelname)s| %(message)s"
)
formatter = logging.Formatter(format_string, datefmt="%Y-%m-%dT%H:%M:%S")
handler = logging.StreamHandler()
@@ -23,14 +26,14 @@ logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
def walk_file(file_path):
def walk_file(file_path, endfix=".py"):
if os.path.isdir(file_path):
for current_path, sub_folders, files_name in os.walk(file_path):
base_name = os.path.basename(current_path)
if base_name in ["migrations"]:
continue
for file in files_name:
if file.endswith(".py"):
if file.endswith(endfix):
file_path = os.path.join(current_path, file)
yield file_path
@@ -56,8 +59,16 @@ def delete_files(files_path):
pass
def delete_folder(file_path):
if os.path.isdir(file_path):
for current_path, sub_folders, files_name in os.walk(file_path):
base_name = os.path.basename(current_path)
if base_name in ["__pycache__"]:
shutil.rmtree(current_path)
def rename_excrypted_file(output_file_path):
files = walk_file(output_file_path)
files = walk_file(output_file_path, endfix=".so")
for file in files:
if file.endswith(".pyd") or file.endswith(".so"):
new_filename = re.sub("(.*)\..*\.(.*)", r"\1.\2", file)
@@ -85,7 +96,7 @@ def encrypt_py(py_files: list):
# os.chdir(dir_name)
logger.debug("正在加密 {}/{}, {}".format(i + 1, total_count, file_name))
logger.debug("encrypted pending {}/{}, {}".format(i + 1, total_count, file_name))
setup(
ext_modules=cythonize([py_file], quiet=True, language_level=3),
@@ -104,9 +115,36 @@ def encrypt_py(py_files: list):
return encrypted_py
if __name__ == '__main__':
encode_dir = "/Users/macbookair/coding/music-tag-web/django_vue_cli/"
fileSet = walk_file(encode_dir)
encrypted_py = encrypt_py(list(fileSet))
def split_list(lst, cnt=8):
size = len(lst) // cnt
remainder = len(lst) % cnt
result = []
start = 0
for i in range(cnt):
if i < remainder:
end = start + size + 1
else:
end = start + size
result.append(lst[start:end])
start = end
return result
def run_work(file_list):
encrypted_py = encrypt_py(file_list)
delete_files(encrypted_py)
rename_excrypted_file(encode_dir)
if __name__ == '__main__':
encode_dir = "/Users/macbookair/coding/music-tag-web/component/translators/"
fileSet = walk_file(encode_dir)
# 切分任务
extensions = split_list(list(fileSet), NB_COMPILE_JOBS)
if extensions:
pool = multiprocessing.Pool(processes=NB_COMPILE_JOBS)
pool.map(run_work, extensions)
pool.close()
pool.join()
print('All processes finished')
rename_excrypted_file(encode_dir)
delete_folder(encode_dir)