Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2
- # -*- coding: utf-8 -*
- __author__ = 'nivs'
- from subprocess import Popen, PIPE
- import threading
- from time import sleep
- def doCommand(command):
- out, err = Popen(command, shell=True, stdout=PIPE).communicate()
- return out
- class myVLC(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.play = True
- self.pid = -1
- self.daemon = True
- def doComand(self, command):
- pp = Popen(command, shell=True, stdout=PIPE)
- self.pid = pp.pid
- pp.communicate()
- def run(self):
- while True:
- if self.play:
- self.doComand("cvlc --volume 256 " +
- "http://radio.spbstu.ru:8000/halls")
- else:
- self.pid = -1
- sleep(1)
- if __name__ == "__main__":
- th = myVLC()
- while True:
- data = doCommand("timeout -s KILL 2 wget -S -q " +
- "http://radio.spbstu.ru:8000/halls " +
- "-O - 2>&1").split("\n")
- if not data[0].find("200") == -1:
- if not th.isAlive():
- th.start()
- th.play = True
- if not data[0].find("404") == -1:
- if not th.pid == -1:
- doCommand("kill -9 %d" % th.pid)
- th.play = False
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment