Skip to content

Commit

Permalink
get currently playing file from mpv process
Browse files Browse the repository at this point in the history
  • Loading branch information
hejops committed Aug 20, 2024
1 parent cb1cf16 commit 1e16f6b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dita/play/pmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def read_queue_file() -> list[str]:
return fobj.read().splitlines()


def mpv_nowplaying() -> str:
return [
proc.as_dict()["open_files"]
for proc in psutil.process_iter()
if proc.name() == "mpv"
][0][-1].path


class Queue:
"""Queue object for managing playback queue"""

Expand Down Expand Up @@ -171,7 +179,12 @@ def open_yt(self):
def open_discogs(self):
"""Open in Discogs release page for currently playing album in
browser"""
url = search_with_relpath(self.np_album).get("uri")
# try current mpv process first
if self.playing:
relpath = mpv_nowplaying().rsplit("/", 1)[0].removeprefix(TARGET_DIR + "/")
else:
relpath = self.np_album
url = search_with_relpath(relpath).get("uri")
if url:
print(url)
open_url(url)
Expand Down

0 comments on commit 1e16f6b

Please sign in to comment.