From 9df6d95924ad9c6a6310ca198b463e9145392201 Mon Sep 17 00:00:00 2001 From: unparalleled-js Date: Sat, 8 Apr 2023 13:22:01 -0500 Subject: [PATCH] fix: afplay fix --- audius/cli/options.py | 2 +- audius/player/af.py | 15 ++++++--------- setup.py | 1 + 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/audius/cli/options.py b/audius/cli/options.py index 621f8a9..572138b 100644 --- a/audius/cli/options.py +++ b/audius/cli/options.py @@ -8,5 +8,5 @@ def player_option(): "--player", help="The player to use.", type=click.Choice([x.value for x in PlayerType.__members__.values()], case_sensitive=False), - callback=lambda _, _2, val: PlayerType(val), + callback=lambda _, _2, val: PlayerType(val) if val else None, ) diff --git a/audius/player/af.py b/audius/player/af.py index 8418280..52ce4e2 100644 --- a/audius/player/af.py +++ b/audius/player/af.py @@ -1,10 +1,11 @@ import os -import subprocess import tempfile import threading import time from typing import TYPE_CHECKING +from afplay import afplay, is_installed + from audius.player.base import BasePlayer from audius.types import PlayerType @@ -16,12 +17,8 @@ class AFPlayer(BasePlayer): def __init__(self, sdk: "Audius"): super().__init__(PlayerType.AFPLAY, sdk) - def is_available(self): - try: - subprocess.run("afplay", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - return True - except FileNotFoundError: - return False + def is_available(self) -> bool: + return is_installed() def play(self, url: str): download_url = self.client.get_redirect_url(url) @@ -35,7 +32,7 @@ def download(): # for entire track to finish download. thread = threading.Thread(target=download) thread.start() - time.sleep(5) # Buffer - subprocess.Popen(["afplay", _file.name]) + time.sleep(3) # Buffer + afplay(_file.name) thread.join() time.sleep(1) diff --git a/setup.py b/setup.py index 9fe906b..bbf6a8e 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ "requests>=2.28.2,<3", "click>=8.1.3,<9", "tqdm>=4.65.0,<5", + "afplay-py>=0.2.0,<0.3", ], python_requires=">=3.9,<4", extras_require=extras_require,