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