nivs

parseVLC

Sep 18th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*
  3. __author__ = 'nivs'
  4.  
  5. from subprocess import Popen, PIPE
  6. import threading
  7. from time import sleep
  8.  
  9.  
  10. def doCommand(command):
  11.     out, err = Popen(command, shell=True, stdout=PIPE).communicate()
  12.     return out
  13.  
  14.  
  15. class myVLC(threading.Thread):
  16.     def __init__(self):
  17.         threading.Thread.__init__(self)
  18.         self.play = True
  19.         self.pid = -1
  20.         self.daemon = True
  21.  
  22.     def doComand(self, command):
  23.         pp = Popen(command, shell=True, stdout=PIPE)
  24.         self.pid = pp.pid
  25.         pp.communicate()
  26.  
  27.     def run(self):
  28.         while True:
  29.             if self.play:
  30.                 self.doComand("cvlc --volume 256 " +
  31.                               "http://radio.spbstu.ru:8000/halls")
  32.             else:
  33.                 self.pid = -1
  34.                 sleep(1)
  35.  
  36.  
  37. if __name__ == "__main__":
  38.     th = myVLC()
  39.  
  40.     while True:
  41.         data = doCommand("timeout -s KILL 2 wget -S -q " +
  42.                          "http://radio.spbstu.ru:8000/halls " +
  43.                          "-O - 2>&1").split("\n")
  44.         if not data[0].find("200") == -1:
  45.             if not th.isAlive():
  46.                 th.start()
  47.             th.play = True
  48.         if not data[0].find("404") == -1:
  49.             if not th.pid == -1:
  50.                 doCommand("kill -9 %d" % th.pid)
  51.             th.play = False
  52.         sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment