subclient

Subsonic ncurses client
git clone https://git.e1e0.net/subclient.git
Log | Files | Refs | README

commit e567ef4b528738568334d3db6c6166431c38f768
parent 94c5c46725154cb27e790ce1af6bff38fadff71c
Author: Paco Esteban <paco@e1e0.net>
Date:   Wed,  9 Jun 2021 18:04:25 +0200

add libmpv wrapper and play streaming directly

Diffstat:
Dplayback.py | 15---------------
Msubclient/subclient.py | 17+++++++++++++++--
2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/playback.py b/playback.py @@ -1,15 +0,0 @@ -import subprocess -import tempfile - - -def play(stream): - """ Initiates a subprocess for the audio player, mpv(1) by default - - :param stream: subsonic stream returned by libsonic.stream() - :type stream: file-like object - """ - with tempfile.NamedTemporaryFile() as fp: - fp.write(stream.read()) - fp.seek(0) - subprocess.call(["mpv", "--no-audio-display", "--really-quiet", - fp.name]) diff --git a/subclient/subclient.py b/subclient/subclient.py @@ -2,9 +2,20 @@ import configparser import libsonic +import mpv from helpers import format_duration -from playback import play + + +player = mpv.MPV(input_default_bindings=True, input_vo_keyboard=True, + vo='gpu', ytdl=True) +stream = None + + +@player.python_stream('subclient') +def stream_reader(): + while True: + yield stream.read(1024*1024) def main(): @@ -23,8 +34,10 @@ def main(): for song in songs['randomSongs']['song']: print(f"Playing: {song['title']} by {song['artist']}" f"({format_duration(song['duration'])})") + global stream stream = subsonic.stream(song['id'], tformat='raw') - play(stream) + player.play('python://subclient') + player.wait_for_playback() if __name__ == "__main__":