From fab9a3d6c4802bac0a4733cdbe1259c6656308dd Mon Sep 17 00:00:00 2001 From: PrajwalVandana <72575914+PrajwalVandana@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:59:28 -0700 Subject: [PATCH] ffmpeg stuff taken care of! --- maestro/helpers.py | 16 ++++----------- maestro/maestro.py | 51 ++++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/maestro/helpers.py b/maestro/helpers.py index eca17b3..fcec101 100644 --- a/maestro/helpers.py +++ b/maestro/helpers.py @@ -3,7 +3,6 @@ import curses import logging import os -import sys import subprocess import threading @@ -15,11 +14,13 @@ import requests from getpass import getpass -from shutil import copy, move, which +from shutil import copy, move from random import randint from time import sleep, time from urllib.parse import quote, quote_plus +from spotdl.utils.ffmpeg import get_ffmpeg_path + from maestro import config from maestro.config import print_to_logfile @@ -27,16 +28,7 @@ # check if ffmpeg is installed without try/except -FFMPEG_PATH = which("ffmpeg") -if FFMPEG_PATH is None: - if sys.platform == "win32": - FFMPEG_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), "../ffmpeg.exe") - ) - else: - FFMPEG_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), "../ffmpeg") - ) +FFMPEG_PATH = str(get_ffmpeg_path()) def is_safe_username(url): diff --git a/maestro/maestro.py b/maestro/maestro.py index 6820c0c..4b6d4bc 100644 --- a/maestro/maestro.py +++ b/maestro/maestro.py @@ -18,6 +18,8 @@ from shutil import move, copy, rmtree from time import sleep, time +from spotdl.utils.ffmpeg import FFmpegError, download_ffmpeg as spotdl_download_ffmpeg + from maestro import config from maestro import helpers from maestro.__version__ import VERSION @@ -49,8 +51,9 @@ def _play( from maestro.mac_presence import ( MacNowPlaying, AppDelegate, - app_helper_loop + app_helper_loop, ) + # pylint: disable=no-name-in-module,import-error from AppKit import ( NSApp, @@ -60,6 +63,7 @@ def _play( NSDate, NSRunLoop, ) + # pylint: enable mac_now_playing = MacNowPlaying() @@ -793,9 +797,7 @@ def cli(): # ensure config.LOGFILE is not too large if os.path.exists(config.LOGFILE) and os.path.getsize(config.LOGFILE) > 1e6: # move to backup - backup_path = os.path.join( - config.OLD_LOG_DIR, f"maestro-{int(t)}.log" - ) + backup_path = os.path.join(config.OLD_LOG_DIR, f"maestro-{int(t)}.log") os.makedirs(os.path.dirname(backup_path), exist_ok=True) move(config.LOGFILE, backup_path) @@ -991,19 +993,27 @@ def spotdl_entry_point(args): finally: sys.argv = original_argv - spotdl_entry_point( - [ - "download", - path_, - "--output", - "{title}.{output-ext}", - "--format", - format_, - "--headless", - "--ffmpeg", - helpers.FFMPEG_PATH, - ], - ) + try: + spotdl_entry_point( + [ + "download", + path_, + "--output", + "{title}.{output-ext}", + "--format", + format_, + "--headless", + "--ffmpeg", + helpers.FFMPEG_PATH, + # "fake", # DEBUG + ], + ) + except FFmpegError: + click.secho( + "FFmpeg is not installed: you can install it globally or run 'maestro download-ffmpeg' to download it internally.", + fg="red", + ) + return paths = [] for fname in os.listdir(config.MAESTRO_DIR): @@ -2758,6 +2768,13 @@ def clear_logs(): click.secho("No logs found.", fg="yellow") +@cli.command(name="download-ffmpeg") +def download_ffmpeg(): + """ + Download the ffmpeg binary for your OS. Required for clip editing. + """ + spotdl_download_ffmpeg() + if __name__ == "__main__": multiprocessing.freeze_support() cli()