From a07f955901d0589acaca3bb7360a8ec578c542d8 Mon Sep 17 00:00:00 2001 From: Tristan Ferrua Date: Fri, 29 Jan 2021 14:18:58 +0000 Subject: [PATCH] Added config file for music_directory and font attributes --- bin/miniplayer | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/miniplayer b/bin/miniplayer index c68434d..cd10e8a 100755 --- a/bin/miniplayer +++ b/bin/miniplayer @@ -2,18 +2,33 @@ import curses import os from mpd import MPDClient +import mpd import ffmpeg import pixcat import time +import configparser from PIL import Image, ImageDraw +# Get config +config = configparser.ConfigParser() +config.read(os.path.expanduser("~/.config/miniplayer/config")) + +if "player" not in config.sections(): + config["player"] = {"music_directory": "~/Music", + "font_width": 11, + "font_height": 24 + } + +playerconfig = config["player"] # Image ratio # Change this to match the (width, height) of your font. -IMAGERATIO = (11, 24) +IMAGERATIO = (playerconfig.getint("font_width", 11), + playerconfig.getint("font_height", 24) + ) # Music directory -MUSICDIR = "~/Music" +MUSICDIR = playerconfig.get("music_directory", "~/Music") MUSICDIR = os.path.expanduser(MUSICDIR) @@ -139,6 +154,7 @@ class Player: A function that extracts the album art from song_file and saves it to self.album_art_loc """ + song_file_abs = os.path.join(MUSICDIR, song_file) process = ( @@ -146,6 +162,7 @@ class Player: .input(song_file_abs) .output(self.album_art_loc) ) + try: process.run(quiet=True, overwrite_output=True) except ffmpeg._run.Error: