Skip to content

Commit

Permalink
json response
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Oct 22, 2021
1 parent aaf1c2e commit 9cdc206
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Binary file modified tiktok_downloader/__pycache__/server.cpython-39.pyc
Binary file not shown.
10 changes: 6 additions & 4 deletions tiktok_downloader/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tiktok_downloader.mdown import mdown
from flask import Flask, request,render_template
from flask import Flask, request,render_template,Response
from . import info_post, snaptik, ssstik, tikmate
import json, os
app = Flask(__name__, template_folder=os.path.abspath(__file__+'/../templates'), static_folder=os.path.abspath(__file__+'/../static'))
Expand Down Expand Up @@ -34,7 +34,7 @@ def snapt(path):
if not request.args.get('url'):
return json.dumps({'msg':'url parameter required'}, indent=4)
resp=info_post(request.args['url'])
return json.dumps({
js=Response(json.dumps({
'account':{
'avatar':resp.account.avatar,
'username':resp.account.username,
Expand All @@ -48,7 +48,9 @@ def snapt(path):
'caption':resp.caption,
'create':resp.create.timestamp(),
'url':resp.url,
'id':resp.id }, indent=4)
'id':resp.id }, indent=4))
js.headers['Content-Type'] = 'application/json'
return js
except Exception as e:
print(e)
return json.dumps({
Expand All @@ -67,7 +69,7 @@ def snapt(path):
res = tikmate().get_media(request.args['url'])
elif path == 'mdown':
res = mdown().get_media(request.args['url'])
return json.dumps([{'type':i.type,'url':i.json} for i in res],indent=4)
return Response(json.dumps([{'type':i.type,'url':i.json} for i in res],indent=4), headers={'Content-Type':'application/json'})
except Exception as e:
print(e)
return json.dumps({
Expand Down

0 comments on commit 9cdc206

Please sign in to comment.