|
1 | 1 | from pydub import AudioSegment
|
2 | 2 | import time
|
3 | 3 | import os
|
| 4 | +import re |
4 | 5 |
|
5 | 6 | import aqt
|
6 | 7 |
|
@@ -39,7 +40,6 @@ def move_extension_mp3_to_media_folder(source, filename):
|
39 | 40 |
|
40 | 41 | def move_extension_mp3_normalize_to_media_folder(source, filename):
|
41 | 42 | path = util.col_media_path(filename)
|
42 |
| - |
43 | 43 | def match_target_amplitude(sound, target_dBFS):
|
44 | 44 | change_in_dBFS = target_dBFS - sound.dBFS
|
45 | 45 | return sound.apply_gain(change_in_dBFS)
|
@@ -69,22 +69,26 @@ def handle_audio_file(file, filename, suffix):
|
69 | 69 | else:
|
70 | 70 | move_extension_mp3_to_media_folder(audio_temp_path, filename)
|
71 | 71 | else:
|
72 |
| - print("moving audio file") |
73 | 72 | move_file_to_media_dir(file, filename)
|
74 | 73 |
|
| 74 | +def handle_file(file_data, only_move=False): |
| 75 | + file_name = file_data["filename"] |
| 76 | + file_body = file_data["body"] |
| 77 | + |
| 78 | + if re.search(r'\?source=.*$', file_name): |
| 79 | + file_name = file_name.split("?source=")[0] |
| 80 | + |
| 81 | + suffix = file_name[-3:] |
| 82 | + |
| 83 | + if suffix in image_formats or only_move: |
| 84 | + move_file_to_media_dir(file_body, file_name) |
| 85 | + elif suffix in audio_formats: |
| 86 | + handle_audio_file(file_body, file_name, suffix) |
75 | 87 |
|
76 | 88 | def handle_files(file_dict, only_move=False):
|
77 | 89 | if not file_dict:
|
78 | 90 | return
|
79 | 91 |
|
80 |
| - for _, sub_file_dicts in file_dict.items(): |
81 |
| - sub_file_dict = sub_file_dicts[0] |
82 |
| - file_name = sub_file_dict["filename"] |
83 |
| - file_body = sub_file_dict["body"] |
84 |
| - |
85 |
| - suffix = file_name[-3:] |
86 |
| - |
87 |
| - if suffix in image_formats or only_move: |
88 |
| - move_file_to_media_dir(file_body, file_name) |
89 |
| - elif suffix in audio_formats: |
90 |
| - handle_audio_file(file_body, file_name, suffix) |
| 92 | + for subs in file_dict.values(): |
| 93 | + for sub in subs: |
| 94 | + handle_file(sub, only_move) |
0 commit comments