Pretty scrolling "now playing" script

2004-06-15
2004-06-15
  • When I used XMMS, I had a script that I wrote to scroll a bigtext display of the current song.  I had it running on a transparent eterm with no border and permanently on the bottom of my window stack.  It looks like the words just scroll up my desktop.

    Now I use otto, so that Steph can pick musing from her machine, too.

    I altered the script so that it now reads what otto is playing instead. 

    The script is below - you need python and figlet to use it.

    #!/usr/bin/python

    numspacers=10
    lines_per_second=12
    spacer="\n "
    lead_in="Now playing:\n"

    import os
    import time
    import urllib

    buffer=[]
    lw=0

    def grabTitle():
        title=""
        got_title=False
        got_artist=False
        otto=urllib.urlopen("http://localhost/otto/otto.cgi/queue")
        for l in otto.readlines():

            l=l.strip()

            if got_title==False and l.find("queue-song")!=-1:
                spos=l.find(">")
                epos=l.find("<",spos);
                title=title+l[spos+1:epos]
                got_title=True
            if got_artist==False and l.find("queue-artist")!=-1:
                l=l[4:]
                spos=l.find(">")
                epos=l.find("<",spos);
                title=title+"\n"+l[spos+1:epos]
                got_artist=True

        otto.close()
        return title

    def getLines():
        global lw,numspacers,spacer,lead_in
        out=[]

        title=grabTitle()
       
        figletw,figletr=os.popen2("figlet -c -t")                  
        print >>figletw,lead_in,title,spacer*numspacers
        figletw.close()
        for l in figletr.readlines():
            out=out+[l[:-1]]
            if len(l[:-1])>lw:
                lw=len(l[:-1])
        return out

    while True:
        if len(buffer)==0:
            buffer=buffer+getLines()
        print buffer[0]
        buffer=buffer[1:]
        time.sleep(1.0/lines_per_second)