Skip to content

fix: strip leading dot from extension when checking audio format on upload#555

Open
octo-patch wants to merge 1 commit intoHuanshere:mainfrom
octo-patch:fix/issue-553-audio-upload-ext-check
Open

fix: strip leading dot from extension when checking audio format on upload#555
octo-patch wants to merge 1 commit intoHuanshere:mainfrom
octo-patch:fix/issue-553-audio-upload-ext-check

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #553

Problem

When a user uploads an MP3 or WAV file, the upload handler gets stuck in a
reload loop and the audio is never processed.

Root cause: os.path.splitext() returns the file extension with a leading
dot (e.g. '.mp3'), but allowed_audio_formats in config.yaml stores
values without the dot (e.g. 'mp3'). The comparison

if ext.lower() in load_key("allowed_audio_formats"):   # '.mp3' in ['mp3', 'wav', ...]

always evaluates to False, so convert_audio_to_video() is never called.
The audio file is saved to the output folder but find_video_files() ignores
it (it only matches video extensions), so the UI loops endlessly on the upload
widget.

This also explains why renaming the file to .mp4 "works" — the video-format
branch is hit instead and find_video_files() picks it up.

Solution

Strip the leading dot with [1:] before the membership test, consistent with
how find_video_files() already handles extensions:

if ext.lower()[1:] in load_key("allowed_audio_formats"):

Testing

  • Uploaded an .mp3 file: the UI now calls convert_audio_to_video, creates
    black_screen.mp4, removes the original audio file, and re-renders showing
    the video player as expected.
  • Uploaded .wav, .flac, .m4a files: same behaviour.
  • Uploaded a .mp4 file: unaffected, works as before.

…ormats (fixes Huanshere#553)

os.path.splitext returns the extension with a leading dot (e.g. '.mp3'),
but allowed_audio_formats entries have no dot (e.g. 'mp3'). The comparison
always evaluated to False, so audio files (MP3, WAV, etc.) were never
converted to a video container and the UI got stuck in a reload loop.

Strip the leading dot with [1:], consistent with how find_video_files()
already handles extensions.

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MP3和WAV处理不了

1 participant