Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*
- #!/usr/bin/python2.7
- __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.daemon = True
- self.play = True
- self.pid = 999999
- 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("vlc --volume 256 http://radio.spbstu.ru:8000/halls")
- # pp = Popen("vlc http://radio.spbstu.ru:8000/halls", shell=True, stdout=PIPE)
- # self.pid = pp.pid
- # pp.communicate()
- sleep(1)
- else:
- doCommand("kill -9 %d" % self.pid)
- #if __name__ == "__main__":
- th = myVLC()
- th.setDaemon(True)
- 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:
- th.play = False
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment