Skip to content

Commit 5958dfd

Browse files
committed
Merge branch 'main' into main-v49-compat
2 parents 15d943a + 9b569d3 commit 5958dfd

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/migaku_connection/card_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def handle_definitions(self, msg_id, definition_data):
9999
self.connection._recv_data(
100100
{"id": msg_id, "msg": "Migaku-Deliver-Definitions", "data": definitions}
101101
)
102-
self.finish("Received defintions from card creator.")
102+
self.finish("Received definitions from card creator.")
103103

104104
def handle_data_from_card_creator(self, jsonData):
105105
r = self._handle_data_from_card_creator(jsonData)

src/migaku_connection/handle_files.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pydub import AudioSegment
22
import time
33
import os
4+
import re
45

56
import aqt
67

@@ -39,7 +40,6 @@ def move_extension_mp3_to_media_folder(source, filename):
3940

4041
def move_extension_mp3_normalize_to_media_folder(source, filename):
4142
path = util.col_media_path(filename)
42-
4343
def match_target_amplitude(sound, target_dBFS):
4444
change_in_dBFS = target_dBFS - sound.dBFS
4545
return sound.apply_gain(change_in_dBFS)
@@ -69,22 +69,26 @@ def handle_audio_file(file, filename, suffix):
6969
else:
7070
move_extension_mp3_to_media_folder(audio_temp_path, filename)
7171
else:
72-
print("moving audio file")
7372
move_file_to_media_dir(file, filename)
7473

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)
7587

7688
def handle_files(file_dict, only_move=False):
7789
if not file_dict:
7890
return
7991

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

Comments
 (0)