Skip to content

Instantly share code, notes, and snippets.

@wdog
Last active November 8, 2020 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdog/f02df3534c62b8dca455d0d26819d8e0 to your computer and use it in GitHub Desktop.
Save wdog/f02df3534c62b8dca455d0d26819d8e0 to your computer and use it in GitHub Desktop.
Simple script for notify-send on song change for mocp player
#!/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)
@wdog
Copy link
Author

wdog commented Nov 7, 2020

USAGE

inside /home/<user>/.moc/config

OnSongChange = "/home/<user>/.moc/songChange.py %f"

  • requires python
  • requires stagger library to read TAGS
pip install stagger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment