SHARE
TWEET

alvare

a guest Apr 15th, 2009 396 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # ALvare-ClrnD
  3. # welcometothechango@gmail.com
  4. # GPLv2
  5. # Listen to Shoutcast in PyQT4
  6.  
  7. import thread, urllib2, os
  8. from xml.etree import ElementTree as ET
  9. from PyQt4 import QtCore, QtGui, uic
  10. from MainWin import Ui_MainWin
  11. #Ui_MainWin, base_class = uic.loadUiType("MainWin.ui")
  12.  
  13. plsurl = 'http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn='
  14. shtcsturl = 'http://www.shoutcast.com/sbin/newxml.phtml?genre='
  15. genre = 'Top500'
  16. terminal = 'gnome-terminal'
  17. player = 'mocp'
  18.  
  19. class PyShoutcast(QtGui.QMainWindow):
  20.         def __init__(self):
  21.                 QtGui.QWidget.__init__(self)
  22.                 self.ui = Ui_MainWin()
  23.                 self.ui.setupUi(self)
  24.                 self.Thread()
  25.                 QtCore.QObject.connect(self.ui.listName,QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.RadioA)
  26.                 QtCore.QObject.connect(self.ui.listGenre,QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.RadioB)
  27.                 QtCore.QObject.connect(self.ui.pushButtonReload,QtCore.SIGNAL("clicked()"), self.Thread)
  28.         def Thread(self):
  29.                 thread.start_new_thread(self.Update,())
  30.         def Update(self):
  31.                 self.ui.listName.clear()
  32.                 self.ui.listGenre.clear()
  33.                 self.station = []
  34.                 try:
  35.                         data = ET.XML(urllib2.urlopen(shtcsturl+genre).read())
  36.                 except urllib2.HTTPError,(fp):
  37.                         self.ui.listName.addItem(str(fp))
  38.                         self.ui.listGenre.addItem(str(fp))
  39.                         return
  40.                 for a in data[1:]:
  41.                         self.ui.listName.addItem(a.attrib['name'])
  42.                         self.ui.listGenre.addItem(a.attrib['genre'])
  43.                         self.station += [a.attrib['id']]
  44.         def RadioA(self):
  45.                 try:
  46.                         pls = urllib2.urlopen(plsurl+self.station[self.ui.listName.currentRow()])
  47.                 except urllib2.HTTPError,(fp):
  48.                         self.ui.listName.currentItem().setText(str(fp))
  49.                         self.ui.listName.currentItem().setForeground(QtGui.QBrush(QtGui.QColor(255,1,1)))
  50.                         return
  51.                 url = pls.readline()
  52.                 url = pls.readline()
  53.                 url = pls.readline()[6:-1]
  54.                 thread.start_new_thread(self.Play,(url,))
  55.         def RadioB(self):
  56.                 try:
  57.                         pls = urllib2.urlopen(plsurl+self.station[self.ui.listGenre.currentRow()])
  58.                 except urllib2.HTTPError,(fp):
  59.                         self.ui.listGenre.currentItem().setText(str(fp))
  60.                         self.ui.listGenre.currentItem().setForeground(QtGui.QBrush(QtGui.QColor(255,1,1)))
  61.                         return
  62.                 url = pls.readline()
  63.                 url = pls.readline()
  64.                 url = pls.readline()[6:-1]
  65.                 thread.start_new_thread(self.Play,(url,))
  66.         def Play(self,url):
  67.                 os.system(terminal+" -e "+"\""+player+" "+url+"\"")
  68.  
  69. app = QtGui.QApplication([])
  70. shtcst = PyShoutcast()
  71. shtcst.show()
  72. exit(app.exec_())
RAW Paste Data
Top