nivs

Untitled

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