Skip to content

Commit

Permalink
[get_song_by_url] Search for relative paths in MPD database only
Browse files Browse the repository at this point in the history
  • Loading branch information
pabera committed Dec 9, 2023
1 parent 472d558 commit 63f5bd2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/jukebox/components/playermpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 63f5bd2

Please sign in to comment.