2019-05-17 22:55:21 -07:00
|
|
|
import resolver
|
|
|
|
|
|
|
|
|
|
from sanic import Sanic, response
|
|
|
|
|
from sanic.exceptions import ServerError, InvalidUsage
|
|
|
|
|
|
|
|
|
|
app = Sanic()
|
|
|
|
|
|
|
|
|
|
|
2019-05-18 14:23:08 -07:00
|
|
|
@app.route('/download/<feed_id>/<video_id>', methods=['GET', 'HEAD'])
|
2019-05-17 22:55:21 -07:00
|
|
|
async def download(req, feed_id, video_id):
|
2019-05-18 14:23:08 -07:00
|
|
|
if req.method == 'HEAD':
|
|
|
|
|
return response.text('')
|
|
|
|
|
|
2019-05-17 22:55:21 -07:00
|
|
|
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)
|