From 8deec2b4992cc0cd883ef690119a1a6ad52ca9c9 Mon Sep 17 00:00:00 2001 From: Bart Kleijngeld Date: Mon, 9 Aug 2021 16:21:55 +0200 Subject: [PATCH] Added possibility to configure what art filenames to try with webserver call --- README.md | 1 + bin/miniplayer | 24 +++++++++++++++--------- config.example | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3302693..d133dc1 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ The config file is located at `~/.config/miniplayer/config`. The example configu #### art * ***music_directory*:** The path to your music directory for extracting album art from the files. * ***http_base_url*:** Base URL of webserver which serves the album art for your albums (takes precedence over `music_directory`). Useful for users of Android MPD clients _MAFA_ or _MPDroid_. For more information see [the MPDroid wiki](https://github.com/abarisain/dmix/wiki/Album-Art-on-your-LAN). +* ***http_cover_filenames*:** Space separated list of filenames to use in the call to the webserver to fetch the album art. * ***image_method*:** The method to use for drawing album art. Available values are `pixcat` and `ueberzug` If you are not using Kitty, try `ueberzug`. diff --git a/bin/miniplayer b/bin/miniplayer index 204047f..bf0d6cb 100755 --- a/bin/miniplayer +++ b/bin/miniplayer @@ -337,17 +337,23 @@ class Player: """ album = os.path.dirname(song_file) - album_art_url = posixpath.join(base_url, album, "cover.jpg") - try: - album_art_resp = requests.get(album_art_url) - except requests.RequestException: - # If any exception occurs, simply give up and show default art. - self.drawDefaultAlbumArt() + for cover_filename in art_config.get("http_cover_filenames").split(): + album_art_url = posixpath.join(base_url, album, cover_filename) - if album_art_resp.ok: - with open(self.album_art_loc, "wb") as f: - f.write(album_art_resp.content) + try: + album_art_resp = requests.get(album_art_url) + except requests.RequestException: + # If any exception occurs, simply give up and show default art. + self.drawDefaultAlbumArt() + break + + if album_art_resp.ok: + with open(self.album_art_loc, "wb") as f: + f.write(album_art_resp.content) + break + elif album_art_resp.status_code == 404: + continue else: self.drawDefaultAlbumArt() diff --git a/config.example b/config.example index ea72a9b..51fbc27 100644 --- a/config.example +++ b/config.example @@ -10,6 +10,7 @@ show_playlist = true image_method = pixcat music_directory = ~/Music # http_base_url = http://localhost:6667/cover-art +# http_cover_filenames = cover.jpg cover.png folder.jpg folder.png art.jpg art.png artwork.jpg artwork.png [mpd] host = localhost