mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-23 03:19:25 +08:00
🈲设置了API开关
This commit is contained in:
parent
656369fc86
commit
029111d768
@ -16,7 +16,6 @@ from scraper import Scraper
|
|||||||
from werkzeug.urls import url_quote
|
from werkzeug.urls import url_quote
|
||||||
from flask import Flask, request, jsonify, make_response
|
from flask import Flask, request, jsonify, make_response
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
headers = {
|
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'
|
'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"])
|
@app.route("/video", methods=["POST", "GET"])
|
||||||
def download_video():
|
def download_video():
|
||||||
# 用于返回视频下载请求(返回MP4文件下载请求,面对大量请求时非常吃服务器内存,容易崩,慎用。)
|
# 用于返回视频下载请求(返回MP4文件下载请求,面对大量请求时非常吃服务器内存,容易崩,慎用。)
|
||||||
|
# 将api_switch的值设定为False可关闭该API
|
||||||
|
api_switch = True
|
||||||
|
if api_switch:
|
||||||
api = Scraper()
|
api = Scraper()
|
||||||
content = request.args.get("url")
|
content = request.args.get("url")
|
||||||
if content == '':
|
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:
|
else:
|
||||||
post_content = find_url(content)[0]
|
post_content = find_url(content)[0]
|
||||||
try:
|
try:
|
||||||
@ -143,15 +146,21 @@ def download_video():
|
|||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify(status='failed', reason=str(e), function='download_video()', value=content)
|
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"])
|
@app.route("/music", methods=["POST", "GET"])
|
||||||
def download_music():
|
def download_music():
|
||||||
# 用于返回视频下载请求(返回MP3文件下载请求,面对大量请求时非常吃服务器内存,容易崩,慎用。)
|
# 用于返回视频下载请求(返回MP3文件下载请求,面对大量请求时非常吃服务器内存,容易崩,慎用。)
|
||||||
|
# 将api_switch的值设定为False可关闭该API
|
||||||
|
api_switch = True
|
||||||
|
if api_switch:
|
||||||
api = Scraper()
|
api = Scraper()
|
||||||
content = request.args.get("url")
|
content = request.args.get("url")
|
||||||
if content == '':
|
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:
|
else:
|
||||||
post_content = find_url(content)[0]
|
post_content = find_url(content)[0]
|
||||||
try:
|
try:
|
||||||
@ -201,6 +210,8 @@ def download_music():
|
|||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify(status='failed', reason=str(e), function='download_music()', value=content)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user