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 from __future__ import annotations
import os import os
import os.path
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import Union from typing import Union

View file

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

View file

@ -4,6 +4,7 @@
from __future__ import annotations from __future__ import annotations
import os import os
import os.path
import platform import platform
import re import re
import subprocess import subprocess
@ -174,14 +175,14 @@ class AVPlayer:
self._stop_if_playing() self._stop_if_playing()
def play_file(self, filename: str) -> None: 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: def play_file_with_caller(self, filename: str, caller: Any) -> None:
self.current_caller = caller self.current_caller = caller
self.play_file(filename) self.play_file(filename)
def insert_file(self, filename: str) -> None: 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() self._play_next_if_idle()
def toggle_pause(self) -> None: def toggle_pause(self) -> None: