forked from kktuax/youtupi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtupi.py
executable file
·64 lines (54 loc) · 1.46 KB
/
youtupi.py
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
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
# -*- coding: utf-8 -*-
import web, json
from StringIO import StringIO
from youtupi.modules.local import module_local
from youtupi.modules.youtube import module_youtube
from youtupi.playlist import prepareVideo, findVideoInPlaylist, removeVideo, playNextVideo, playVideo, addVideo, controlPlayer, playList
class redirect:
def GET(self, path):
web.seeother('/' + path)
class index:
def GET(self):
web.seeother('/static/index.html')
class playlist:
def GET(self):
playlistVideos = list()
for video in playList():
playlistVideos.append(video.data)
return json.dumps(playlistVideos, indent=4)
def POST(self):
data = json.load(StringIO(web.data()))
addVideo(data)
web.seeother('/playlist')
def DELETE(self):
data = json.load(StringIO(web.data()))
removeVideo(data['id'])
web.seeother('/playlist')
class control:
def GET(self, action):
if action == "play":
playNextVideo()
else:
controlPlayer(action)
web.seeother('/playlist')
def POST(self, action):
if action == "play":
data = json.load(StringIO(web.data()))
video = findVideoInPlaylist(data['id'])
if video:
prepareVideo(video)
playVideo(data['id'])
web.seeother('/playlist')
if __name__ == "__main__":
urls = (
'/(.*)/', 'redirect',
'/playlist', 'playlist',
'/video/(.*)', 'video',
'/control/(.*)', 'control',
'/local', module_local,
'/youtube', module_youtube,
'/', 'index'
)
app = web.application(urls, globals())
app.run()