trim file to basename before creating SoundOrVideoTag (#4057)

* trim file to basename before creating SoundOrVideoTag

* add import

(cherry picked from commit 29e3146e1f)
This commit is contained in:
Ren Tatsumoto 2025-06-04 11:03:14 +00:00 committed by Damien Elmes
parent afb3eb7fd8
commit b5d23f7c0e
3 changed files with 6 additions and 3 deletions

View file

@ -10,6 +10,7 @@ These can be accessed via eg card.question_av_tags()
from __future__ import annotations
import os
import os.path
import re
from dataclasses import dataclass
from typing import Union

View file

@ -28,6 +28,7 @@ template_legacy.py file, using the legacy addHook() system.
from __future__ import annotations
import os.path
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any, Union
@ -92,7 +93,7 @@ class PartiallyRenderedCard:
def av_tag_to_native(tag: card_rendering_pb2.AVTag) -> AVTag:
val = tag.WhichOneof("value")
if val == "sound_or_video":
return SoundOrVideoTag(filename=tag.sound_or_video)
return SoundOrVideoTag(filename=os.path.basename(tag.sound_or_video))
else:
return TTSTag(
field_text=tag.tts.field_text,

View file

@ -4,6 +4,7 @@
from __future__ import annotations
import os
import os.path
import platform
import re
import subprocess
@ -174,14 +175,14 @@ class AVPlayer:
self._stop_if_playing()
def play_file(self, filename: str) -> None:
self.play_tags([SoundOrVideoTag(filename=filename)])
self.play_tags([SoundOrVideoTag(filename=os.path.basename(filename))])
def play_file_with_caller(self, filename: str, caller: Any) -> None:
self.current_caller = caller
self.play_file(filename)
def insert_file(self, filename: str) -> None:
self._enqueued.insert(0, SoundOrVideoTag(filename=filename))
self._enqueued.insert(0, SoundOrVideoTag(filename=os.path.basename(filename)))
self._play_next_if_idle()
def toggle_pause(self) -> None: