Skip to content

Commit

Permalink
Fix mass audio creation
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel committed Sep 28, 2024
1 parent ef4c84b commit 9b569d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/migaku_connection/card_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def handle_definitions(self, msg_id, definition_data):
self.connection._recv_data(
{"id": msg_id, "msg": "Migaku-Deliver-Definitions", "data": definitions}
)
self.finish("Received defintions from card creator.")
self.finish("Received definitions from card creator.")

def handle_data_from_card_creator(self, jsonData):
r = self._handle_data_from_card_creator(jsonData)
Expand Down
30 changes: 17 additions & 13 deletions src/migaku_connection/handle_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydub import AudioSegment
import time
import os
import re

import aqt

Expand Down Expand Up @@ -39,7 +40,6 @@ def move_extension_mp3_to_media_folder(source, filename):

def move_extension_mp3_normalize_to_media_folder(source, filename):
path = util.col_media_path(filename)

def match_target_amplitude(sound, target_dBFS):
change_in_dBFS = target_dBFS - sound.dBFS
return sound.apply_gain(change_in_dBFS)
Expand Down Expand Up @@ -69,22 +69,26 @@ def handle_audio_file(file, filename, suffix):
else:
move_extension_mp3_to_media_folder(audio_temp_path, filename)
else:
print("moving audio file")
move_file_to_media_dir(file, filename)

def handle_file(file_data, only_move=False):
file_name = file_data["filename"]
file_body = file_data["body"]

if re.search(r'\?source=.*$', file_name):
file_name = file_name.split("?source=")[0]

suffix = file_name[-3:]

if suffix in image_formats or only_move:
move_file_to_media_dir(file_body, file_name)
elif suffix in audio_formats:
handle_audio_file(file_body, file_name, suffix)

def handle_files(file_dict, only_move=False):
if not file_dict:
return

for _, sub_file_dicts in file_dict.items():
sub_file_dict = sub_file_dicts[0]
file_name = sub_file_dict["filename"]
file_body = sub_file_dict["body"]

suffix = file_name[-3:]

if suffix in image_formats or only_move:
move_file_to_media_dir(file_body, file_name)
elif suffix in audio_formats:
handle_audio_file(file_body, file_name, suffix)
for subs in file_dict.values():
for sub in subs:
handle_file(sub, only_move)

0 comments on commit 9b569d3

Please sign in to comment.