Skip to content

Commit 4dea4e9

Browse files
committed
remove metadata from files before transcoding
1 parent b455559 commit 4dea4e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

podme_api/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import contextlib
67
from dataclasses import dataclass
78
from datetime import date, datetime, time
89
from http import HTTPStatus
@@ -344,6 +345,8 @@ async def transcode_file(
344345
Base Media format). Most likely this can be solved in better ways, but this will do for now.
345346
If the audio is served to clients in the original container (version 5 as of now), they will
346347
be very confused about the total duration of the file, for some reason...
348+
We also remove any metadata from the file prior to transcoding, mainly to avoid issues with
349+
badly encoded Unicode data in there.
347350
348351
Args:
349352
input_file (PathLike | str): The path to the audio file.
@@ -359,10 +362,29 @@ async def transcode_file(
359362

360363
if output_file is None: # pragma: no cover
361364
output_file = input_file.with_stem(f"{input_file.stem}_out")
365+
output_interim_file = input_file.with_stem(f"{input_file.stem}_interim")
362366

363367
transcode_options = transcode_options or {}
364368

365369
try:
370+
_LOGGER.debug("Clearing metadata from file: %s", input_file.name)
371+
with contextlib.suppress(UnicodeDecodeError):
372+
await (
373+
FFmpeg()
374+
.input(input_file)
375+
.output(
376+
output_interim_file,
377+
{
378+
"map_metadata": "-1",
379+
"c": "copy",
380+
},
381+
)
382+
.execute()
383+
)
384+
385+
input_file.unlink()
386+
output_interim_file.rename(input_file)
387+
366388
ffprobe = FFmpeg(executable="ffprobe").input(
367389
input_file,
368390
print_format="json",

0 commit comments

Comments
 (0)