-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
70 lines (52 loc) · 1.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import httpx
from dotenv import load_dotenv
from flask import (
Flask,
request,
Response,
render_template,
redirect,
stream_with_context,
)
from core.feed import render_feed
from core.options import GlobalOptions
from core.plugin.plugin_factory import PluginFactory
load_dotenv()
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html", host_url=request.host_url)
@app.route("/feed")
def feed():
options = GlobalOptions(**request.args)
feed_generator = PluginFactory.create(options.service, request.args)
return Response(
render_feed(options.id, feed_generator, options, request.host_url),
mimetype="application/rss+xml",
content_type="text/xml",
)
@app.route("/download")
def download():
options = GlobalOptions(**request.args)
url = PluginFactory.create(options.service, request.args).get_item_url(options.id)
if options.proxy_download:
req = httpx.get(url, stream=True)
return Response(
stream_with_context(req.iter_content()),
content_type=req.headers["content-type"],
)
else:
return redirect(url, code=302)
@app.route("/health-check")
def health_check():
return "OK"
@app.errorhandler(404)
def page_not_found(e):
return "Sorry, Nothing at this URL.", 404
@app.errorhandler(500)
def application_error(e):
return "Sorry, unexpected error: {}".format(e), 500
if __name__ == "__main__":
port = os.getenv("PODTUBE_PORT")
app.run(host="0.0.0.0", port=int(port) if port and port.isdigit() else 8080)