ditched libmpv, invoke mpv directly... much more reliable
This commit is contained in:
parent
1193580403
commit
c9add5fa96
3 changed files with 23 additions and 36 deletions
|
@ -16,10 +16,8 @@ syng-shell = "syng.webclientmockup:main"
|
||||||
python = "^3.7"
|
python = "^3.7"
|
||||||
pytube = "^12.1.0"
|
pytube = "^12.1.0"
|
||||||
aiohttp = "^3.8.3"
|
aiohttp = "^3.8.3"
|
||||||
python-mpv = "^1.0.1"
|
|
||||||
python-socketio = "^5.7.2"
|
python-socketio = "^5.7.2"
|
||||||
minio = "^7.1.12"
|
minio = "^7.1.12"
|
||||||
colored = "^1.4.4"
|
|
||||||
mutagen = "^1.46.0"
|
mutagen = "^1.46.0"
|
||||||
aiocmd = "^0.1.5"
|
aiocmd = "^0.1.5"
|
||||||
pyqrcode = "^1.2.1"
|
pyqrcode = "^1.2.1"
|
||||||
|
|
|
@ -6,10 +6,11 @@ from asyncio import Future
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
from mpv import MPV
|
|
||||||
import mutagen
|
import mutagen
|
||||||
|
|
||||||
from .source import Source, async_in_thread, available_sources
|
from .source import Source, async_in_thread, available_sources
|
||||||
|
from .common import play_mpv, kill_mpv
|
||||||
from ..result import Result
|
from ..result import Result
|
||||||
from ..entry import Entry
|
from ..entry import Entry
|
||||||
|
|
||||||
|
@ -46,31 +47,23 @@ class S3Source(Source):
|
||||||
)
|
)
|
||||||
raise RuntimeError(f"Could not parse {filename}")
|
raise RuntimeError(f"Could not parse {filename}")
|
||||||
|
|
||||||
@async_in_thread
|
async def play(self, entry) -> None:
|
||||||
def play(self, entry) -> None:
|
|
||||||
while not entry.uuid in self.downloaded_files:
|
while not entry.uuid in self.downloaded_files:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
self.downloaded_files[entry.uuid]["lock"].wait()
|
self.downloaded_files[entry.uuid]["lock"].wait()
|
||||||
|
|
||||||
self.player = MPV(
|
|
||||||
input_default_bindings=True,
|
|
||||||
input_vo_keyboard=True,
|
|
||||||
osc=True,
|
|
||||||
fullscreen=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
cdg_file = self.downloaded_files[entry.uuid]["cdg"]
|
cdg_file = self.downloaded_files[entry.uuid]["cdg"]
|
||||||
mp3_file = self.downloaded_files[entry.uuid]["mp3"]
|
mp3_file = self.downloaded_files[entry.uuid]["mp3"]
|
||||||
|
|
||||||
self.player.loadfile(
|
self.player = await play_mpv(
|
||||||
cdg_file,
|
cdg_file, mp3_file, ["--scale=oversample", "--fullscreen"]
|
||||||
mode="replace",
|
|
||||||
audio_file=mp3_file,
|
|
||||||
scale="oversample",
|
|
||||||
)
|
)
|
||||||
self.player.wait_for_playback()
|
|
||||||
self.player.terminate()
|
await self.player.wait()
|
||||||
|
|
||||||
|
async def skip_current(self) -> None:
|
||||||
|
await self.player.kill()
|
||||||
|
|
||||||
@async_in_thread
|
@async_in_thread
|
||||||
def get_config(self):
|
def get_config(self):
|
||||||
|
|
|
@ -3,8 +3,8 @@ import shlex
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from pytube import YouTube, Search, Channel, innertube
|
from pytube import YouTube, Search, Channel, innertube
|
||||||
from mpv import MPV
|
|
||||||
|
|
||||||
|
from .common import play_mpv, kill_mpv
|
||||||
from .source import Source, async_in_thread, available_sources
|
from .source import Source, async_in_thread, available_sources
|
||||||
from ..entry import Entry
|
from ..entry import Entry
|
||||||
from ..result import Result
|
from ..result import Result
|
||||||
|
@ -15,29 +15,25 @@ class YoutubeSource(Source):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.innertube_client = innertube.InnerTube(client="WEB")
|
self.innertube_client = innertube.InnerTube(client="WEB")
|
||||||
self.channels = config["channels"] if "channels" in config else []
|
self.channels = config["channels"] if "channels" in config else []
|
||||||
self.player = None
|
self.player: None | asyncio.subprocess.Process = None
|
||||||
|
|
||||||
async def get_config(self):
|
async def get_config(self):
|
||||||
return {"channels": self.channels}
|
return {"channels": self.channels}
|
||||||
|
|
||||||
@async_in_thread
|
async def play(self, entry: Entry) -> None:
|
||||||
def play(self, entry: Entry) -> None:
|
self.player = await play_mpv(
|
||||||
self.player = MPV(
|
entry.id,
|
||||||
input_default_bindings=True,
|
None,
|
||||||
input_vo_keyboard=True,
|
[
|
||||||
osc=True,
|
"--script-opts=ytdl_hook-ytdl_path=yt-dlp,ytdl_hook-exclude='%.pls$'",
|
||||||
ytdl=True,
|
"--ytdl-format=bestvideo[height<=720]+bestaudio/best[height<=720]",
|
||||||
script_opts="ytdl_hook-ytdl_path=yt-dlp,ytdl_hook-exclude='%.pls$'",
|
"--fullscreen",
|
||||||
ytdl_format="bestvideo[height<=720]+bestaudio/best[height<=720]",
|
],
|
||||||
fullscreen=True,
|
|
||||||
)
|
)
|
||||||
self.player.play(entry.id)
|
await self.player.wait()
|
||||||
self.player.wait_for_playback()
|
|
||||||
self.player.terminate()
|
|
||||||
|
|
||||||
async def skip_current(self) -> None:
|
async def skip_current(self) -> None:
|
||||||
loop = asyncio.get_event_loop()
|
await self.player.kill()
|
||||||
await loop.run_in_executor(None, self.player.terminate)
|
|
||||||
|
|
||||||
@async_in_thread
|
@async_in_thread
|
||||||
def get_entry(self, performer: str, url: str) -> Entry:
|
def get_entry(self, performer: str, url: str) -> Entry:
|
||||||
|
|
Loading…
Add table
Reference in a new issue