trim file to basename before creating SoundOrVideoTag (#4057)

* trim file to basename before creating SoundOrVideoTag

* add import
This commit is contained in:
Ren Tatsumoto 2025-06-04 11:03:14 +00:00 committed by GitHub
parent 996fa8bcb0
commit 29e3146e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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
@ -95,7 +96,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
@ -176,7 +177,7 @@ 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:
if self.current_caller: if self.current_caller:
@ -185,7 +186,7 @@ class AVPlayer:
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: