🈲设置了API开关

This commit is contained in:
Evil0ctal 2022-04-06 21:02:44 -07:00 committed by GitHub
parent 656369fc86
commit 029111d768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,6 @@ from scraper import Scraper
from werkzeug.urls import url_quote
from flask import Flask, request, jsonify, make_response
app = Flask(__name__)
headers = {
'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36 Edg/87.0.664.66'
@ -91,10 +90,14 @@ def webapi():
@app.route("/video", methods=["POST", "GET"])
def download_video():
# 用于返回视频下载请求(返回MP4文件下载请求面对大量请求时非常吃服务器内存容易崩慎用。)
# 将api_switch的值设定为False可关闭该API
api_switch = True
if api_switch:
api = Scraper()
content = request.args.get("url")
if content == '':
return jsonify(status='failed', reason='url value cannot be empty', function='download_music()', value=content)
return jsonify(status='failed', reason='url value cannot be empty', function='download_music()',
value=content)
else:
post_content = find_url(content)[0]
try:
@ -143,15 +146,21 @@ def download_video():
return response
except Exception as e:
return jsonify(status='failed', reason=str(e), function='download_video()', value=content)
else:
return jsonify(Status='Failed', Reason='This API is disabled. To enable it, set the value of "api_switch" to True.')
@app.route("/music", methods=["POST", "GET"])
def download_music():
# 用于返回视频下载请求(返回MP3文件下载请求面对大量请求时非常吃服务器内存容易崩慎用。)
# 将api_switch的值设定为False可关闭该API
api_switch = True
if api_switch:
api = Scraper()
content = request.args.get("url")
if content == '':
return jsonify(status='failed', reason='url value cannot be empty', function='download_music()', value=content)
return jsonify(status='failed', reason='url value cannot be empty', function='download_music()',
value=content)
else:
post_content = find_url(content)[0]
try:
@ -201,6 +210,8 @@ def download_music():
return response
except Exception as e:
return jsonify(status='failed', reason=str(e), function='download_music()', value=content)
else:
return jsonify(Status='Failed', Reason='This API is disabled. To enable it, set the value of "api_switch" to True.')
if __name__ == '__main__':