1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00
2019-05-18 14:23:08 -07:00

31 lines
820 B
Python

import resolver
from sanic import Sanic, response
from sanic.exceptions import ServerError, InvalidUsage
app = Sanic()
@app.route('/download/<feed_id>/<video_id>', methods=['GET', 'HEAD'])
async def download(req, feed_id, video_id):
if req.method == 'HEAD':
return response.text('')
try:
redirect_url = resolver.download(feed_id, video_id)
return response.redirect(redirect_url)
except resolver.InvalidUsage:
raise InvalidUsage()
except resolver.QuotaExceeded:
raise ServerError('Too many requests. Daily limit is 1000. Consider upgrading account to get unlimited access.',
status_code=429)
@app.get('/ping')
async def ping(req):
return response.text('pong')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)