Last active
November 8, 2020 11:09
-
-
Save wdog/f02df3534c62b8dca455d0d26819d8e0 to your computer and use it in GitHub Desktop.
Simple script for notify-send on song change for mocp player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import argparse | |
import stagger | |
def notify(song, album, artist, icon='music'): | |
command = f''' | |
notify-send -i "{icon}" "π΅ {song}" "<i>π {album}</i>\n<b>π {artist}</b>" | |
''' | |
os.system(command) | |
def get_cover(mp3): | |
if (mp3.picture): | |
data = mp3[stagger.id3.APIC][0].data | |
icon = '/tmp/xyz.jpg' | |
with open(icon, "wb") as outfile: | |
outfile.write(data) | |
else: | |
icon = 'music' | |
return icon | |
def main(filename): | |
mp3 = stagger.read_tag(filename) | |
icon = get_cover(mp3) | |
notify(mp3.title, mp3.album, mp3.artist, icon) | |
def check_file(filename): | |
try: | |
f = open(filename) | |
# Do something with the file | |
except IOError: | |
print("File not accessible") | |
return False | |
finally: | |
f.close() | |
return True | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument("filename") | |
args = parser.parse_args() | |
if check_file(args.filename): | |
main(args.filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE
inside /home/<user>/.moc/config
OnSongChange = "/home/<user>/.moc/songChange.py %f"