Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio with hashtags in filenames are not loaded #3124

Closed
gotev opened this issue May 25, 2024 · 1 comment · Fixed by #3138
Closed

Audio with hashtags in filenames are not loaded #3124

gotev opened this issue May 25, 2024 · 1 comment · Fixed by #3138
Labels
bug Something isn't working
Milestone

Comments

@gotev
Copy link
Contributor

gotev commented May 25, 2024

Description

I have a folder with two audio files and I'm trying to play them:

  • artist - #title.mp3
  • artist - title.mp3

Minimal app:

from nicegui import ui, native
import urllib
from pathlib import Path

ui.audio(src="artist - #title.mp3", controls=True)  # this triggers an error
ui.audio(src=urllib.parse.quote_plus("artist - #title.mp3"),
         controls=True)  # this triggers an error
ui.audio(src=Path("artist - #title.mp3"),
         controls=True)  # this triggers an error
ui.audio(src="artist - title.mp3", controls=True)  # this works

ui.run(
    reload=False,
    native=True,
    dark=True,
    port=native.find_open_port(),
    title='Audio Demo'
)

When the app is run this is what I see on screen:
Screenshot 2024-05-25 alle 09 51 52

And this is what I see in the console:

$ python app.py
NiceGUI ready to go on http:https://localhost:8002
http:https://127.0.0.1:8002/artist+-+#title.mp3 not found
http:https://127.0.0.1:8002/_nicegui/auto/media/9ea021d92f620e392dc6848d57e79cca/artist -  not found
http:https://127.0.0.1:8002/_nicegui/auto/media/9ea021d92f620e392dc6848d57e79cca/artist -  not found

using Python 3.11.7 on macOS Sonoma 14.4

Tried URL escaping the file name and parsing file name with Path, but without success. Has this already happened to others before?

@afullerx
Copy link
Contributor

afullerx commented May 27, 2024

This seems to be due to an oversight where file names are not escaped when the URL is generated. I experimentally added the escaping to App.add_media_file() using urllib.parse.quote() and the provided example seems to be working. I'll submit a pull request once I do some more testing, unless anyone else has a better idea. I would do the same to App.add_static_file()

Edit: Doing the escaping yourself doesn't work because the code checks to see if it's a file. If the file name is already escaped, it fails and the correct URL isn't generated.

@falkoschindler falkoschindler added the bug Something isn't working label May 31, 2024
@falkoschindler falkoschindler added this to the 1.4.27 milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants