-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain.py
121 lines (94 loc) · 3.56 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
@Time : 2023/3/25 19:47
@Author : superhero
@Email : [email protected]
@File : main.py
@IDE: PyCharm
"""
import json
from gevent import monkey
monkey.patch_all()
from flask import Flask, jsonify, request, redirect, make_response
from flask_cors import CORS
import musicapi
from gevent.pywsgi import WSGIServer
from gevent.pool import Pool
application = Flask(__name__, static_folder='templates/static')
application.json.ensure_ascii = False
CORS(application, resources=r'/*')
def __set_no_cache(res):
response = make_response(redirect(res, code=301))
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = "0"
response.headers["Pragma"] = "no-cache"
response.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8"
return response
@application.route(rule="/kugou/<song_id>", methods=["GET", "POST"])
def kugou_url(song_id):
MusicApi = musicapi.MusicApi_kugou(song_id)
ret = MusicApi.get_kugou_url(song_id)
return __set_no_cache(ret)
@application.route(rule="/kugou/lrc/<song_id>.lrc", methods=["GET", "POST"])
def kugou_lrc(song_id):
MusicApi = musicapi.MusicApi_kugou(song_id)
ret = MusicApi.get_kugou_lrc(song_id)
return ret
@application.route(rule="/wyy/<song_id>", methods=["GET", "POST"])
def wyy_url(song_id):
MusicApi = musicapi.MusicApi_wyy('')
ret = MusicApi.get_wyy_url(song_id)
return __set_no_cache(ret)
@application.route(rule="/wyy/lrc/<song_id>.lrc", methods=["GET", "POST"])
def wyy_lrc(song_id):
MusicApi = musicapi.MusicApi_wyy('')
ret = MusicApi.get_wyy_lrc(song_id)
return ret
@application.route(rule="/qqmusic/<song_id>", methods=["GET", "POST"])
def qqmusic_url(song_id):
MusicApi = musicapi.MusicApi_qq('')
ret = MusicApi.get_qq_url(song_id)
return __set_no_cache(ret)
@application.route(rule="/qqmusic/lrc/<song_id>.lrc")
def qqmusic_lrc(song_id):
MusicApi = musicapi.MusicApi_qq('')
ret = MusicApi.get_qq_lrc(song_id)
return ret
@application.route(rule="/kuwo/<song_id>", methods=["GET", "POST"])
def kuwo_url(song_id):
MusicApi = musicapi.MusicApi_kuwo('')
ret = MusicApi.get_kuwo_url(song_id)
return __set_no_cache(ret)
@application.route(rule="/kuwo/lrc/<song_id>.lrc", methods=["GET", "POST"])
def kuwo_lrc(song_id):
MusicApi = musicapi.MusicApi_kuwo('')
return MusicApi.get_kuwo_lrc(song_id)
@application.route(rule="/kuwo/random_music_list", methods=["GET", "POST"])
def kuwo_random_list():
MusicApi = musicapi.MusicApi_kuwo('')
return MusicApi.random_music_list
@application.route('/music/songlist', methods=['POST', 'GET'])
def music_songlist():
server = request.values.get('server', '')
t_id = request.values.get('id', '')
music_info = musicapi.MusicApi_kuwo(t_id)
if server and t_id:
if server == 'kugou':
resp = music_info.get_kugou_list
elif server == 'wyy':
resp = music_info.get_wyy_list
elif server == 'qqmusic':
resp = music_info.get_qq_list
elif server == 'kuwo':
resp = music_info.get_kuwo_list
else:
resp = {'msg': '暂不支持此平台'}
else:
resp = {'msg': '缺少必要参数'}
response = make_response(json.dumps(resp, ensure_ascii=False, separators=(",", ":")))
response.headers["Content-Type"] = "application/json"
return response
if __name__ == "__main__":
print("MusicApi start run")
http_server = WSGIServer(('0.0.0.0', 7878), application, spawn=Pool(50))
http_server.serve_forever()