-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
95 lines (81 loc) · 3.01 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import hug
api = hug.API(__name__)
api.http.add_middleware(hug.middleware.CORSMiddleware(api, max_age=10))
@hug.response_middleware()
def CORS(request, response, resource):
response.set_header('Access-Control-Allow-Origin', '*')
response.set_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
response.set_header('Access-Control-Allow-Headers',
'Authorization,Keep-Alive,User-Agent,'
'If-Modified-Since,Cache-Control,Content-Type')
response.set_header('Access-Control-Expose-Headers',
'Authorization,Keep-Alive,User-Agent,'
'If-Modified-Since,Cache-Control,Content-Type'
)
if request.method == 'OPTIONS':
response.set_header('Access-Control-Max-Age', 1728000)
response.set_header('Content-Type', 'text/plain charset=UTF-8')
response.set_header('Content-Length', 0)
response.status_code = hug.HTTP_204
def error_msg_handle(exp):
from backend.yclogger import slacklog
from backend.yclogger import stacklogger
tracebackmsg = stacklogger.format(exp)
slacklog.error("{}".format(tracebackmsg))
return {'status': 'error',
'message': "{}".format(exp),
'traceback': "{}".format(tracebackmsg)
}
@hug.get('/api/song')
def song(url):
try:
from backend.yclogger import telelog
from crawler.cmder import CrawlCmder
from backend.type import Cmder
telelog.debug('```{}```'.format(url))
cmder = CrawlCmder({'url': url})
songinfo = cmder.run()
return songinfo.toJSON()
except Exception as exp:
return error_msg_handle(exp)
@hug.post('/api/video/render')
def publish(body):
try:
from Api.publish import publish_vid
from handler import handler_publish
from handler import handler_render
from backend.yclogger import telelog
telelog.info(body)
status = handler_render(body)
return status
except Exception as exp:
return error_msg_handle(exp)
return {'url': 'render started'}
#
#
@hug.post('/api/video/publish')
def publish(body):
try:
from Api.publish import publish_vid
from handler import handler_publish
from backend.yclogger import telelog
telelog.info('RELEASE: {}'.format(body))
status = handler_publish(body)
return status
except Exception as exp:
return error_msg_handle(exp)
return {'url': 'render started'}
#
#
@hug.post('/api/video/filmrecap')
def film_recap(body):
try:
from Api.publish import publish_vid
from handler import handler_filmmaker
from backend.yclogger import telelog
telelog.info('RELEASE: {}'.format(body))
status = handler_filmmaker(body)
return status
except Exception as exp:
return error_msg_handle(exp)
return {'url': 'render started'}