From 63f5bd22c352c03bb71182f1f7b3336c232d73c0 Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 10 Dec 2023 00:31:16 +0100 Subject: [PATCH] [get_song_by_url] Search for relative paths in MPD database only --- src/jukebox/components/playermpd/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/jukebox/components/playermpd/__init__.py b/src/jukebox/components/playermpd/__init__.py index ecac65ab8..3975fdb67 100644 --- a/src/jukebox/components/playermpd/__init__.py +++ b/src/jukebox/components/playermpd/__init__.py @@ -80,6 +80,7 @@ # Toggle (und 2nd Swipe generell) ist immer vom Status des Zielsystems abhängig und kann damit nur vom Zielsystem geändert # werden. Bei Wifi also braucht man 3 Funktionen: on / off / toggle. Toggle ist dann first swipe / second swipe +import os import mpd import threading import logging @@ -574,6 +575,11 @@ def list_song_by_artist_and_album(self, albumartist, album): @plugs.tag def get_song_by_url(self, song_url): + # MPD can play absolute paths but can find songs in its database only by relative path + # In certain situations, `song_url` can be an absolute path. Then, it will be trimed to be relative + _music_library_path_absolute = os.path.expanduser(components.player.get_music_library_path()) + song_url = song_url.replace(f'{_music_library_path_absolute}/', '') + with self.mpd_lock: song = self.mpd_retry_with_mutex(self.mpd_client.find, 'file', song_url)