mirror of https://github.com/morpheus65535/bazarr
Merge remote-tracking branch 'origin/Flask' into Flask
This commit is contained in:
commit
f26ab05e89
|
@ -6,7 +6,7 @@ import datetime
|
||||||
import pretty
|
import pretty
|
||||||
|
|
||||||
from get_args import args
|
from get_args import args
|
||||||
from config import settings
|
from config import settings, base_url
|
||||||
|
|
||||||
from init import *
|
from init import *
|
||||||
import logging
|
import logging
|
||||||
|
@ -19,7 +19,7 @@ from flask import Flask, jsonify, request, Response, Blueprint
|
||||||
|
|
||||||
from flask_restful import Resource, Api
|
from flask_restful import Resource, Api
|
||||||
|
|
||||||
api_bp = Blueprint('api', __name__, url_prefix='/api')
|
api_bp = Blueprint('api', __name__, url_prefix=base_url.rstrip('/')+'/api')
|
||||||
api = Api(api_bp)
|
api = Api(api_bp)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ from io import BytesIO
|
||||||
from six import text_type, PY2
|
from six import text_type, PY2
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from get_languages import load_language_in_db, language_from_alpha3, language_from_alpha2, alpha2_from_alpha3
|
from get_languages import load_language_in_db, language_from_alpha3, language_from_alpha2, alpha2_from_alpha3
|
||||||
from flask import Flask, make_response, request, redirect, abort, render_template, Response, session, flash, url_for, send_file
|
from flask import Flask, make_response, request, redirect, abort, render_template, Response, session, flash, url_for, \
|
||||||
|
send_file, stream_with_context
|
||||||
|
|
||||||
from get_providers import get_providers, get_providers_auth, list_throttled_providers
|
from get_providers import get_providers, get_providers_auth, list_throttled_providers
|
||||||
from get_series import *
|
from get_series import *
|
||||||
|
@ -65,27 +66,23 @@ from flask_debugtoolbar import DebugToolbarExtension
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
class PrefixMiddleware(object):
|
def prefix_route(route_function, prefix='', mask='{0}{1}'):
|
||||||
|
# Defines a new route function with a prefix.
|
||||||
def __init__(self, app, prefix=''):
|
# The mask argument is a `format string` formatted with, in that order: prefix, route
|
||||||
self.app = app
|
def newroute(route, *args, **kwargs):
|
||||||
self.prefix = prefix
|
# New function to prefix the route
|
||||||
|
return route_function(mask.format(prefix, route), *args, **kwargs)
|
||||||
def __call__(self, environ, start_response):
|
return newroute
|
||||||
|
|
||||||
if environ['PATH_INFO'].startswith(self.prefix):
|
|
||||||
environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):]
|
|
||||||
environ['SCRIPT_NAME'] = self.prefix
|
|
||||||
return self.app(environ, start_response)
|
|
||||||
else:
|
|
||||||
start_response('404', [('Content-Type', 'text/plain')])
|
|
||||||
return ["This url does not belong to the app.".encode()]
|
|
||||||
|
|
||||||
# Flask Setup
|
# Flask Setup
|
||||||
app = Flask(__name__,
|
app = Flask(__name__,
|
||||||
template_folder=os.path.join(os.path.dirname(__file__), '..', 'views'),
|
template_folder=os.path.join(os.path.dirname(__file__), '..', 'views'),
|
||||||
static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'))
|
static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'))
|
||||||
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=base_url)
|
app.route = prefix_route(app.route, base_url.rstrip('/'))
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def http_error_handler(error):
|
||||||
|
return redirect(base_url.rstrip('/')), 302
|
||||||
|
|
||||||
app.config["SECRET_KEY"] = 'test'
|
app.config["SECRET_KEY"] = 'test'
|
||||||
|
|
||||||
|
@ -511,17 +508,13 @@ def download_log():
|
||||||
@login_required
|
@login_required
|
||||||
def image_proxy(url):
|
def image_proxy(url):
|
||||||
apikey = settings.sonarr.apikey
|
apikey = settings.sonarr.apikey
|
||||||
url_image = url_sonarr_short() + '/' + url + '?apikey=' + apikey
|
url_image = (url_sonarr_short() + '/' + url + '?apikey=' + apikey).replace('poster-250', 'poster-500')
|
||||||
try:
|
try:
|
||||||
image_buffer = BytesIO(
|
req = requests.get(url_sonarr() + '/api' + url_image.split(url_sonarr())[1], stream=True, timeout=15, verify=False)
|
||||||
requests.get(url_sonarr() + '/api' + url_image.split(url_sonarr())[1], timeout=15, verify=False).content)
|
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
image_buffer.seek(0)
|
return Response(stream_with_context(req.iter_content(2048)), content_type=req.headers['content-type'])
|
||||||
bytes = image_buffer.read()
|
|
||||||
request.set_header('Content-type', 'image/jpeg')
|
|
||||||
return bytes
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/image_proxy_movies/<path:url>', methods=['GET'])
|
@app.route('/image_proxy_movies/<path:url>', methods=['GET'])
|
||||||
|
@ -530,17 +523,12 @@ def image_proxy_movies(url):
|
||||||
apikey = settings.radarr.apikey
|
apikey = settings.radarr.apikey
|
||||||
try:
|
try:
|
||||||
url_image = (url_radarr_short() + '/' + url + '?apikey=' + apikey).replace('/fanart.jpg', '/banner.jpg')
|
url_image = (url_radarr_short() + '/' + url + '?apikey=' + apikey).replace('/fanart.jpg', '/banner.jpg')
|
||||||
image_buffer = BytesIO(
|
req = requests.get(url_radarr() + '/api' + url_image.split(url_radarr())[1], stream=True, timeout=15, verify=False)
|
||||||
requests.get(url_radarr() + '/api' + url_image.split(url_radarr())[1], timeout=15, verify=False).content)
|
|
||||||
except:
|
except:
|
||||||
url_image = url_radarr_short() + '/' + url + '?apikey=' + apikey
|
url_image = url_radarr_short() + '/' + url + '?apikey=' + apikey
|
||||||
image_buffer = BytesIO(
|
req = requests.get(url_radarr() + '/api' + url_image.split(url_radarr())[1], stream=True, timeout=15, verify=False)
|
||||||
requests.get(url_radarr() + '/api' + url_image.split(url_radarr())[1], timeout=15, verify=False).content)
|
|
||||||
else:
|
else:
|
||||||
image_buffer.seek(0)
|
return Response(stream_with_context(req.iter_content(2048)), content_type=req.headers['content-type'])
|
||||||
bytes = image_buffer.read()
|
|
||||||
request.set_header('Content-type', 'image/jpeg')
|
|
||||||
return bytes
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
|
Loading…
Reference in New Issue