remove mopidy
This commit is contained in:
parent
5c24306cfc
commit
bb88ba86ca
1 changed files with 2 additions and 63 deletions
|
@ -8,9 +8,7 @@ from abc import ABC, abstractmethod
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import requests
|
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from mfrc522.SimpleMFRC522 import SimpleMFRC522
|
from mfrc522.SimpleMFRC522 import SimpleMFRC522
|
||||||
|
@ -278,68 +276,9 @@ class DebugRenderer(Renderer):
|
||||||
return (self.start != 0) and (self.get_time() - self.offset < 10)
|
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:
|
def main(media_path: str, renderer_type: str) -> None:
|
||||||
if renderer_type == "dummy":
|
if renderer_type == "dummy":
|
||||||
renderer = DebugRenderer()
|
renderer = DebugRenderer()
|
||||||
elif renderer_type == "mopidy":
|
|
||||||
renderer = MopidyRenderer()
|
|
||||||
else:
|
else:
|
||||||
renderer = DebugRenderer()
|
renderer = DebugRenderer()
|
||||||
player = Player(media_path=media_path, renderer=renderer)
|
player = Player(media_path=media_path, renderer=renderer)
|
||||||
|
@ -363,8 +302,8 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--renderer",
|
"--renderer",
|
||||||
choices=("dummy", "mopidy"),
|
choices=("dummy"),
|
||||||
default="mopidy",
|
default="dummy",
|
||||||
help="media renderer to use as backend",
|
help="media renderer to use as backend",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue