playerctl wrapper to query now playing song info

This commit is contained in:
Ferit Yiğit BALABAN 2022-04-19 23:40:10 +03:00
parent b78fc7cd6b
commit 0c2c09b899

25
nowplaying.py Executable file
View File

@ -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()