Skipping playback now works reliably
This commit is contained in:
parent
824198acf6
commit
d4cf649735
3 changed files with 46 additions and 25 deletions
|
@ -119,15 +119,21 @@ class State:
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, config: dict[str, Any]):
|
def __init__(self, config: dict[str, Any]):
|
||||||
self.sio = socketio.AsyncClient(json=jsonencoder)
|
self.sio = socketio.AsyncClient(json=jsonencoder)
|
||||||
self.skipped = False
|
self.skipped = []
|
||||||
self.config = config
|
|
||||||
self.sources = configure_sources(config["sources"])
|
self.sources = configure_sources(config["sources"])
|
||||||
self.state = State()
|
self.state = State()
|
||||||
self.currentLock = asyncio.Semaphore(0)
|
self.currentLock = asyncio.Semaphore(0)
|
||||||
print("blubb")
|
self.player = Player(f"{config['config']['server']}/{config['config']['room']}", self.quit)
|
||||||
self.player = Player()
|
|
||||||
self.register_handlers()
|
self.register_handlers()
|
||||||
|
|
||||||
|
def quit(self, event):
|
||||||
|
e = event.as_dict()
|
||||||
|
if e["event"] == b"shutdown":
|
||||||
|
quit()
|
||||||
|
# if value is None:
|
||||||
|
# return
|
||||||
|
# print(value)
|
||||||
|
|
||||||
def register_handlers(self) -> None:
|
def register_handlers(self) -> None:
|
||||||
self.sio.on("update_config", self.handle_update_config)
|
self.sio.on("update_config", self.handle_update_config)
|
||||||
self.sio.on("skip-current", self.handle_skip_current)
|
self.sio.on("skip-current", self.handle_skip_current)
|
||||||
|
@ -166,11 +172,12 @@ class Client:
|
||||||
:rtype: None
|
:rtype: None
|
||||||
"""
|
"""
|
||||||
logger.info("Skipping current")
|
logger.info("Skipping current")
|
||||||
|
self.skipped.append(data["uuid"])
|
||||||
|
|
||||||
entry = Entry(**data)
|
entry = Entry(**data)
|
||||||
print("Skipping: ", entry.title)
|
print("Skipping: ", entry.title)
|
||||||
source = self.sources[entry.source]
|
source = self.sources[entry.source]
|
||||||
|
|
||||||
self.skipped = True
|
|
||||||
await source.skip_current(Entry(**data))
|
await source.skip_current(Entry(**data))
|
||||||
self.player.skip_current()
|
self.player.skip_current()
|
||||||
# if self.state.current_source is not None:
|
# if self.state.current_source is not None:
|
||||||
|
@ -283,20 +290,20 @@ class Client:
|
||||||
f"Playing: {entry.artist} - {entry.title} [{entry.album}] "
|
f"Playing: {entry.artist} - {entry.title} [{entry.album}] "
|
||||||
f"({entry.source}) for {entry.performer}"
|
f"({entry.source}) for {entry.performer}"
|
||||||
)
|
)
|
||||||
|
print(entry)
|
||||||
|
print(self.skipped)
|
||||||
|
if entry.uuid not in self.skipped:
|
||||||
try:
|
try:
|
||||||
# self.state.current_source = self.sources[entry.source]
|
|
||||||
if self.state.config["preview_duration"] > 0:
|
if self.state.config["preview_duration"] > 0:
|
||||||
await self.preview(entry)
|
await self.preview(entry)
|
||||||
video, audio = await source.ensure_playable(entry)
|
video, audio = await source.ensure_playable(entry)
|
||||||
|
if entry.uuid not in self.skipped:
|
||||||
|
self.skipped = []
|
||||||
await self.player.play(video, audio, source.extra_mpv_options)
|
await self.player.play(video, audio, source.extra_mpv_options)
|
||||||
# await self.sources[entry.source].play(
|
|
||||||
# entry, self.player, self.state.config["mpv_options"]
|
|
||||||
# )
|
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
print_exc()
|
print_exc()
|
||||||
self.state.current_source = None
|
|
||||||
if self.skipped:
|
if self.skipped:
|
||||||
self.skipped = False
|
self.skipped.remove(entry.uuid)
|
||||||
await self.sio.emit("get-first")
|
await self.sio.emit("get-first")
|
||||||
else:
|
else:
|
||||||
await self.sio.emit("pop-then-get-next")
|
await self.sio.emit("pop-then-get-next")
|
||||||
|
@ -353,14 +360,16 @@ class Client:
|
||||||
"""
|
"""
|
||||||
if data["success"]:
|
if data["success"]:
|
||||||
logger.info("Registered")
|
logger.info("Registered")
|
||||||
|
qr_string = f"{self.state.config['server']}/{data['room']}"
|
||||||
|
self.player.update_qr(qr_string)
|
||||||
# this is borked on windows
|
# this is borked on windows
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
print(f"Join here: {self.state.config['server']}/{data['room']}")
|
print(f"Join here: {self.state.config['server']}/{data['room']}")
|
||||||
qr = QRCode(box_size=20, border=2)
|
qr = QRCode(box_size=20, border=2)
|
||||||
qr.add_data(f"{self.state.config['server']}/{data['room']}")
|
qr.add_data(qr_string)
|
||||||
qr.make()
|
qr.make()
|
||||||
qr.print_ascii()
|
qr.print_ascii()
|
||||||
|
|
||||||
self.state.config["room"] = data["room"]
|
self.state.config["room"] = data["room"]
|
||||||
await self.sio.emit("sources", {"sources": list(self.sources.keys())})
|
await self.sio.emit("sources", {"sources": list(self.sources.keys())})
|
||||||
if self.state.current_source is None: # A possible race condition can occur here
|
if self.state.current_source is None: # A possible race condition can occur here
|
||||||
|
|
|
@ -13,15 +13,15 @@ __dirname__ = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self) -> None:
|
def __init__(self, qr_string: str, quit_callback) -> None:
|
||||||
locale.setlocale(locale.LC_ALL, "C")
|
locale.setlocale(locale.LC_ALL, "C")
|
||||||
self.mpv = mpv.MPV(ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True)
|
self.mpv = mpv.MPV(ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True)
|
||||||
|
self.mpv.title = "Syng - Player"
|
||||||
self.mpv.keep_open = "yes"
|
self.mpv.keep_open = "yes"
|
||||||
self.qr_overlay: Optional[mpv.ImageOverlay] = None
|
self.qr_overlay: Optional[mpv.ImageOverlay] = None
|
||||||
qr = QRCode(box_size=5, border=1)
|
self.update_qr(
|
||||||
qr.add_data("https://syng.rocks/")
|
qr_string,
|
||||||
qr.make()
|
)
|
||||||
self.qr = qr.make_image().convert("RGBA")
|
|
||||||
|
|
||||||
self.mpv.play(
|
self.mpv.play(
|
||||||
f"{__dirname__}/static/background.png",
|
f"{__dirname__}/static/background.png",
|
||||||
|
@ -33,6 +33,17 @@ class Player:
|
||||||
|
|
||||||
self.mpv.observe_property("osd-width", self.osd_size_handler)
|
self.mpv.observe_property("osd-width", self.osd_size_handler)
|
||||||
self.mpv.observe_property("osd-height", self.osd_size_handler)
|
self.mpv.observe_property("osd-height", self.osd_size_handler)
|
||||||
|
# self.mpv.register_event_callback(quit_callback)
|
||||||
|
# self.mpv.observe_property("exit-handler", quit_callback)
|
||||||
|
|
||||||
|
def event_printer(self, *args):
|
||||||
|
print(args)
|
||||||
|
|
||||||
|
def update_qr(self, qr_string: str) -> None:
|
||||||
|
qr = QRCode(box_size=5, border=1)
|
||||||
|
qr.add_data(qr_string)
|
||||||
|
qr.make()
|
||||||
|
self.qr = qr.make_image().convert("RGBA")
|
||||||
|
|
||||||
def osd_size_handler(self, attribute: str, value: int) -> None:
|
def osd_size_handler(self, attribute: str, value: int) -> None:
|
||||||
if self.qr_overlay:
|
if self.qr_overlay:
|
||||||
|
|
|
@ -16,6 +16,7 @@ class MPV:
|
||||||
sub_pos: int
|
sub_pos: int
|
||||||
osd_width: str
|
osd_width: str
|
||||||
osd_height: str
|
osd_height: str
|
||||||
|
title: str
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, ytdl: bool, input_default_bindings: bool, input_vo_keyboard: bool, osc: bool
|
self, ytdl: bool, input_default_bindings: bool, input_vo_keyboard: bool, osc: bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue