Skip to content

Commit

Permalink
ffmpeg stuff taken care of!
Browse files Browse the repository at this point in the history
  • Loading branch information
PrajwalVandana committed Jul 23, 2024
1 parent 7ef0129 commit fab9a3d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
16 changes: 4 additions & 12 deletions maestro/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import curses
import logging
import os
import sys
import subprocess
import threading

Expand All @@ -15,28 +14,21 @@
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

# endregion


# 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):
Expand Down
51 changes: 34 additions & 17 deletions maestro/maestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -60,6 +63,7 @@ def _play(
NSDate,
NSRunLoop,
)

# pylint: enable

mac_now_playing = MacNowPlaying()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit fab9a3d

Please sign in to comment.