From bb88ba86ca1b908b41e577ed3200a64372ea9740 Mon Sep 17 00:00:00 2001 From: Asaril Date: Mon, 15 May 2023 01:59:59 +0200 Subject: [PATCH] remove mopidy --- src/sleepywaves.py | 65 ++-------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/src/sleepywaves.py b/src/sleepywaves.py index 531ce69..5bcc2fd 100644 --- a/src/sleepywaves.py +++ b/src/sleepywaves.py @@ -8,9 +8,7 @@ from abc import ABC, abstractmethod import logging import os import os.path -import requests import time -import urllib.parse from dataclasses import dataclass from mfrc522.SimpleMFRC522 import SimpleMFRC522 @@ -278,68 +276,9 @@ class DebugRenderer(Renderer): return (self.start != 0) and (self.get_time() - self.offset < 10) -class MopidyRenderer(Renderer): - def __init__(self) -> None: - super().__init__() - self._id = 1 - self._post("core.tracklist.clear") - self._post("core.tracklist.set_consume", [True]) - self._post("core.tracklist.set_single", [True]) - - def get_tracks(self, path: str) -> list[str]: - all_files = os.listdir(path) - return sorted([f for f in all_files if f.endswith(".mp3")]) - - def play(self, path: str, from_time: int) -> None: - log.info(f"MopidyRenderer: play({path}, {from_time})") - quoted_path = urllib.parse.quote(path) - uri = f"file://{quoted_path}" - added_tracks = self._post("core.tracklist.add", {"uris": [uri]}) - tlid = added_tracks[0]["tlid"] - self._post("core.playback.play", {"tlid": tlid}) - if from_time > 0: - playing = self.is_playing() - while not playing: - time.sleep(0.1) - playing = self.is_playing() - seeked = False - while not seeked: - time.sleep(0.1) - seeked = self._post( - "core.playback.seek", {"time_position": from_time * 1000} - ) - - def get_time(self) -> int: - res = self._post("core.playback.get_time_position") - return int(res / 1000) - - def stop(self) -> None: - log.info("MopidyRenderer: stop()") - self._post("core.playback.stop") - self._post("core.tracklist.clear") - - def is_playing(self) -> bool: - res = self._post("core.playback.get_state") - return res == "playing" - - def _post( - self, method: str, data: Union[Dict[str, Any], List[Any], None] = None - ) -> Any: - msg: Dict[str, Any] = {"jsonrpc": "2.0", "id": self._id, "method": method} - if data is not None: - msg["params"] = data - log.debug(f"MopidyRenderer POST: {msg}") - response = requests.post("http://localhost:6680/mopidy/rpc", json=msg).json() - log.debug(f"MopidyRenderer POST response: {response}") - self._id += 1 - return response["result"] - - def main(media_path: str, renderer_type: str) -> None: if renderer_type == "dummy": renderer = DebugRenderer() - elif renderer_type == "mopidy": - renderer = MopidyRenderer() else: renderer = DebugRenderer() player = Player(media_path=media_path, renderer=renderer) @@ -363,8 +302,8 @@ if __name__ == "__main__": ) parser.add_argument( "--renderer", - choices=("dummy", "mopidy"), - default="mopidy", + choices=("dummy"), + default="dummy", help="media renderer to use as backend", )