Merge pull request #278 from Monadical-SAS/mp3-download-fix

Fix MP3 download python error
This commit is contained in:
Andreas Bonini
2023-10-13 10:49:08 +01:00
committed by GitHub
4 changed files with 12 additions and 6 deletions

View File

@@ -38,7 +38,9 @@ def _get_range_header(range_header: str, file_size: int) -> tuple[int, int]:
return start, end
def range_requests_response(request: Request, file_path: str, content_type: str):
def range_requests_response(
request: Request, file_path: str, content_type: str, content_disposition: str
):
"""Returns StreamingResponse using Range Requests of a given file"""
file_size = os.stat(file_path).st_size
@@ -54,6 +56,10 @@ def range_requests_response(request: Request, file_path: str, content_type: str)
"content-range, content-encoding"
),
}
if content_disposition:
headers["Content-Disposition"] = content_disposition
start = 0
end = file_size - 1
status_code = status.HTTP_200_OK

View File

@@ -363,7 +363,7 @@ async def transcript_get_audio_mp3(
request,
transcript.audio_mp3_filename,
content_type="audio/mpeg",
headers={"Content-Disposition": f"attachment; filename={filename}"},
content_disposition=f"attachment; filename={filename}",
)

View File

@@ -35,7 +35,7 @@ async def fake_transcript(tmpdir):
@pytest.mark.parametrize(
"url_suffix,content_type",
[
["/mp3", "audio/mp3"],
["/mp3", "audio/mpeg"],
],
)
async def test_transcript_audio_download(fake_transcript, url_suffix, content_type):
@@ -51,7 +51,7 @@ async def test_transcript_audio_download(fake_transcript, url_suffix, content_ty
@pytest.mark.parametrize(
"url_suffix,content_type",
[
["/mp3", "audio/mp3"],
["/mp3", "audio/mpeg"],
],
)
async def test_transcript_audio_download_range(
@@ -74,7 +74,7 @@ async def test_transcript_audio_download_range(
@pytest.mark.parametrize(
"url_suffix,content_type",
[
["/mp3", "audio/mp3"],
["/mp3", "audio/mpeg"],
],
)
async def test_transcript_audio_download_range_with_seek(

View File

@@ -167,7 +167,7 @@ async def test_transcript_rtc_and_websocket(
# check that audio/mp3 is available
resp = await ac.get(f"/transcripts/{tid}/audio/mp3")
assert resp.status_code == 200
assert resp.headers["Content-Type"] == "audio/mp3"
assert resp.headers["Content-Type"] == "audio/mpeg"
# stop server
server.stop()