-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
52 lines (47 loc) · 1.62 KB
/
server.py
File metadata and controls
52 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import ctypes
import os,random,subprocess
from urlparse import parse_qs
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
PORT_NUMBER = 8081
vlc_pid = None
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
global vlc_pid
path = self.path
parse = parse_qs(path[2:])
print parse['function']
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
if((parse['function'][0])=="lock"):
ctypes.windll.user32.LockWorkStation()
# Send the html message
self.wfile.write("PC Will be Locked")
return
if((parse['function'][0])=="friends"):
if(vlc_pid):
vlc_pid.kill()
season = ("0"+str(random.randint(1,10)))[-2:]
season_path = "H:\TV Series\Friends\Friends Season "+str(season)+" [720p]"
random_file_path = random.choice(os.listdir(season_path))
while(random_file_path[-4:]==".srt"):
random_file_path = random.choice(os.listdir(season_path))
print "Playing FRIENDS Episode"+random_file_path
vlc_pid = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe",season_path+"\\"+random_file_path])
self.wfile.write("Playing FRIENDS Episode "+random_file_path)
return
return
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()