diff --git a/.gitignore b/.gitignore index 13d1490..dd1d1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,4 @@ dmypy.json # Pyre type checker .pyre/ - +.idea diff --git a/main.py b/main.py new file mode 100644 index 0000000..27f5319 --- /dev/null +++ b/main.py @@ -0,0 +1,40 @@ +# -*- coding:utf-8 -*- +import os +import re +from ffmpeg import audio + +root_dir = r'I:\work\SVN\new_shenghua\chengxu\client\res\sound' + + +def get_files(path): + res = [] + r = os.listdir(path) # 列出文件夹下所有的目录与文件 + for i in r: + file_path = os.path.join(path, i) + if os.path.isfile(file_path) and file_path.endswith('mp3'): + if re.match(r'.*x[\d\.]+\.mp3$', file_path): + continue + res.append(file_path) + return res + + +def change_speed(file, x, error_info): + res = audio.a_speed(file, x, re.sub(r'(\.mp3$)', f'_x{x}.mp3', file)) + if not res: + error_info.append(f'{file} to {x} error') + + +def run(): + files = get_files(root_dir) + error_info = [] + for file in files: + change_speed(file, '1.5', error_info) + change_speed(file, '3', error_info) + + print('*'*20) + for i in error_info: + print(i) + + +if __name__ == "__main__": + run()