-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathplayer.py
62 lines (52 loc) · 1.5 KB
/
player.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
# -*- coding:utf8 -*-
import os
import web
import player_core
web.config.debug = False
player_core = player_core.player()
render = web.template.render('templates/playlist')
urls = (
'/play', 'play',
'/add', 'modify',
'/remove', 'modify',
'/control', 'control',
'/show', 'show'
)
base_dir = '/Users/jialeicui/Music'
class play:
def POST(self):
post = web.input()
if post['position'] == 'local':
player_core.play(os.path.join(base_dir, post['path']))
elif post['position'] == 'remote':
player_core.play('http://' + post['path'])
return ''
class modify:
def POST(self):
post = web.input()
action = post['action']
if action == 'add':
source = ''
if post['position'] == 'local':
source = os.path.join(base_dir, post['path'])
elif post['position'] == 'remote':
source = 'http://' + post['path']
player_core.add(source, post['title'])
elif action == 'remove':
return player_core.remove(int(post['id']))
return ''
class control:
def POST(self):
post = web.input()
if post['action'] == 'next':
player_core.next()
pass
return ''
class show:
def GET(self):
plist = player_core.get_list()
for x in xrange(0, len(plist)):
plist[x]['id'] = x
pass
return render.index(plist)
app_player = web.application(urls, locals())