From 0c2c09b8994c5efa646c140ae7f037a71ff4ff15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Tue, 19 Apr 2022 23:40:10 +0300 Subject: [PATCH] playerctl wrapper to query now playing song info --- nowplaying.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 nowplaying.py diff --git a/nowplaying.py b/nowplaying.py new file mode 100755 index 0000000..3481fbc --- /dev/null +++ b/nowplaying.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import subprocess as s + + +def main(): + l = str(s.run(['playerctl', 'metadata'], capture_output=True, text=True).stdout).splitlines() + if len(l) == 0: + print('') + exit(0) + artist = '' + title = '' + s_artist = 'chromium xesam:artist' + s_title = 'chromium xesam:title' + for x in l: + if s_artist in x: + artist = x.split(s_artist)[1].strip() + elif s_title in x: + title = x.split(s_title)[1].strip() + break + print(f'{artist} - {title}') + + +if __name__ == '__main__': + main() +