Hente band og sang fra Spotify
I Linux bruker jeg et program som heter Conky. Conky lar deg hente ut alt mulig av info fra PCen, og sette det opp slik du selv vil. Siden jeg er en ivrig bruker av Spotify, hadde jeg lyst til å hente ut sang og artist fra Spotify, og legge det til Conky. Dette er kommandoen jeg bruker:
xwininfo -children -root|grep Spotify -
Jeg vet ikke om det finnes noe alternativ til Conky i Windows, men denne kommandoen gjør noenlunde samme nytten der:
TASKLIST /FO CSV /FI "WINDOWTITLE eq Spotify*" /V
For å få outputten i en litt mer brukervennlig form, kan man bruke et lite Python-skript, noe ala dette:
#!/usr/bin/python
# coding:utf-8
import subprocess
import sys
os = sys.platform
if 'linux' in os:
spotify = subprocess.Popen('xwininfo -children -root|grep Spotify - ', shell=True, stdout=subprocess.PIPE)
spotify = spotify.stdout.read()
spotify = spotify.split('Spotify - ')[1].split('": ')[0]
spotify = spotify.split(' – ')
band = spotify[0]
song = spotify[1]
elif 'windows' in os:
spotify = subprocess.Popen('TASKLIST /FO CSV /FI "WINDOWTITLE eq Spotify*" /V', shell=True, stdin=subprocess.PIPE)
spotify = spotify.stdout.read()
spotify = spotify.split('","')[-1]
spotify = spotify.split(' - ')
band = spotify[1]
song = spotify[2].replace('"', '')
else:
print 'Platform not supported.'
print '''
Band: '''+band+'''
Song: '''+song+'''
'''
14. Nov, 2009 kl. 21:08
Olav. Hele Vennesla VGS computer-geek. :)