mirror of
https://github.com/Suxiaoqinx/Netease_url.git
synced 2025-09-14 11:36:45 +08:00
Update main.py
增加多个参数 url&ids
This commit is contained in:
parent
f06080a844
commit
c86eb16696
37
main.py
37
main.py
@ -7,7 +7,6 @@ from random import randrange
|
|||||||
import requests
|
import requests
|
||||||
from cryptography.hazmat.primitives import padding
|
from cryptography.hazmat.primitives import padding
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
|
|
||||||
def HexDigest(data):
|
def HexDigest(data):
|
||||||
# Digests a `bytearray` to a hex string
|
# Digests a `bytearray` to a hex string
|
||||||
return "".join([hex(d)[2:].zfill(2) for d in data])
|
return "".join([hex(d)[2:].zfill(2) for d in data])
|
||||||
@ -89,25 +88,45 @@ def read_cookie():
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
|
||||||
|
def hello_world():
|
||||||
|
return '你好,世界!'
|
||||||
|
|
||||||
@app.route('/Song_V1',methods=['GET','POST'])
|
@app.route('/Song_V1',methods=['GET','POST'])
|
||||||
|
|
||||||
def Song_v1():
|
def Song_v1():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
# 从查询字符串中获取所有参数的值
|
||||||
song_ids = request.args.get('ids')
|
song_ids = request.args.get('ids')
|
||||||
|
url = request.args.get('url')
|
||||||
level = request.args.get('level')
|
level = request.args.get('level')
|
||||||
type = request.args.get('type')
|
type = request.args.get('type')
|
||||||
else:
|
else:
|
||||||
song_ids = request.form.get('ids')
|
song_ids = request.form.get('ids')
|
||||||
|
url = request.form.get('url')
|
||||||
level = request.form.get('level')
|
level = request.form.get('level')
|
||||||
type = request.form.get('type')
|
type = request.form.get('type')
|
||||||
|
|
||||||
if song_ids is None:
|
# 检查至少提供一个 'ids' 或 'url' 参数
|
||||||
return jsonify({'error': 'ids参数为空'}), 400
|
if not song_ids and url is None:
|
||||||
|
return jsonify({'error': '必须提供 ids 或 url 参数'}), 400
|
||||||
if level is None:
|
if level is None:
|
||||||
return jsonify({'error': 'level参数为空'}), 400
|
return jsonify({'error': 'level参数为空'}), 400
|
||||||
if type is None:
|
if type is None:
|
||||||
return jsonify({'error': 'type参数为空'}), 400
|
return jsonify({'error': 'type参数为空'}), 400
|
||||||
|
|
||||||
|
# Check if either song_ids or url is provided
|
||||||
|
if song_ids:
|
||||||
|
# Process song_ids
|
||||||
|
jsondata = song_ids
|
||||||
|
elif url:
|
||||||
|
# Process url
|
||||||
|
jsondata = url
|
||||||
|
else:
|
||||||
|
# Neither song_ids nor url provided
|
||||||
|
return jsonify({'error': '错误!'}), 400
|
||||||
|
|
||||||
# 网易云cookie
|
# 网易云cookie
|
||||||
cookies = parse_cookie(read_cookie())
|
cookies = parse_cookie(read_cookie())
|
||||||
|
|
||||||
@ -122,7 +141,7 @@ def Song_v1():
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'ids': [ids(song_ids)],
|
'ids': [ids(jsondata)],
|
||||||
'level': level,
|
'level': level,
|
||||||
'encodeType': 'flac',
|
'encodeType': 'flac',
|
||||||
'header': json.dumps(config),
|
'header': json.dumps(config),
|
||||||
@ -143,11 +162,12 @@ def Song_v1():
|
|||||||
params = HexDigest(enc)
|
params = HexDigest(enc)
|
||||||
# 发送POST请求
|
# 发送POST请求
|
||||||
response = post(url, params, cookies)
|
response = post(url, params, cookies)
|
||||||
|
#print(response)
|
||||||
if "参数错误" in response:
|
if "参数错误" in response:
|
||||||
return jsonify({"status": 400,'msg': '参数错误!'}), 400
|
return jsonify({"status": 400,'msg': '参数错误!'}), 400
|
||||||
|
|
||||||
jseg = json.loads(response)
|
jseg = json.loads(response)
|
||||||
song_names = "https://music.163.com/api/v3/song/detail"
|
song_names = "https://interface3.music.163.com/api/v3/song/detail"
|
||||||
data = {'c': json.dumps([{"id":jseg['data'][0]['id'],"v":0}])}
|
data = {'c': json.dumps([{"id":jseg['data'][0]['id'],"v":0}])}
|
||||||
resp = requests.post(url=song_names, data=data)
|
resp = requests.post(url=song_names, data=data)
|
||||||
jse = json.loads(resp.text)
|
jse = json.loads(resp.text)
|
||||||
@ -185,7 +205,6 @@ def Song_v1():
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.config['JSON_SORT_KEYS'] = False
|
app.config['JSON_SORT_KEYS'] = True
|
||||||
app.config['JSON_AS_ASCII']=False
|
app.config['JSON_AS_ASCII'] = True
|
||||||
#默认调试模式为False关闭 端口默认为5000
|
app.run(host='0.0.0.0', port=5000, debug=False)
|
||||||
app.run(debug=False,port=5000)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user