Skip to content

Instantly share code, notes, and snippets.

@klardotsh
Last active April 6, 2021 02:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klardotsh/8234727 to your computer and use it in GitHub Desktop.
Save klardotsh/8234727 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
die() { echo ""; exit; }
pidof cmus >/dev/null || die
statu=`cmus-remote -Q | grep status`
[ "${statu}" == "status playing" ] || die
stream=`cmus-remote -Q | grep file | grep http`
title=`cmus-remote -Q | grep -m 1 title | cut -d' ' -f3-`
artist=`cmus-remote -Q | grep -v aaa_mode | grep -v albumartist | grep -m 1 artist | cut -d' ' -f3-`
if [[ ! -z $stream ]]; then
streamURL=`echo ${stream} | cut -d' ' -f2`
streamData=`python2 ${HOME}/bin/shoutcast_meta.py ${streamURL} | cut -d"'" -f2`
if `echo ${title} | grep "cliqhop" > /dev/null`; then
title="soma.fm :: cliqhop"
else
if `echo ${title} | grep "public safety radio" > /dev/null`; then
title="soma.fm :: sf-1033"
else
if `echo ${title} | grep "Soma" > /dev/null`; then
title="soma.fm :: $(echo ${title} | cut -d':' -f1)"
fi
fi
fi
echo "${streamData} - ${title} "
else
echo "${artist} - ${title}"
fi
#!/usr/bin/env python2
import urllib2
import sys
request = urllib2.Request(sys.argv[1])
request.add_header('Icy-MetaData','1')
opener = urllib2.build_opener()
data=opener.open(request)
headers=True
while headers:
line = data.readline()
if line[0:11]=="icy-metaint":
interval = int(line[12:])
if line=="\r\n":
headers=False
data.read(interval)
len=ord(data.read(1))*16
#print "Meta data is",len
print data.read(len)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment