You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
import json |
|
import os |
|
|
|
from flask import Flask, render_template |
|
|
|
|
|
def create_app(): |
|
# create and configure the app |
|
app = Flask(__name__, instance_relative_config=True) |
|
app.config.from_mapping( |
|
SECRET_KEY = 'dev', |
|
DATABASE = os.path.join(app.instance_path, 'video_metadata.sqlite'), |
|
MOVIE_DIR = os.path.join(app.instance_path, 'movie_dir'), |
|
TMDB_API_KEY = parse_API_key(app, os.path.join(app.instance_path, 'API_KEY.json')), |
|
TEMPLATES_AUTO_RELOAD = True, |
|
) |
|
|
|
# ensure the instance folder exists |
|
try: |
|
os.makedirs(app.instance_path) |
|
except OSError: |
|
pass |
|
|
|
from . import db |
|
db.init_app(app) |
|
|
|
from video_metadata.views import file_listing |
|
app.register_blueprint(file_listing.bp) |
|
|
|
from video_metadata.views import tmdb |
|
app.register_blueprint(tmdb.bp) |
|
|
|
app.add_url_rule('/', 'index', index) |
|
|
|
return app |
|
|
|
|
|
def index(): |
|
return render_template('index.html') |
|
|
|
def parse_API_key(app, path): |
|
try: |
|
fd = open(path) |
|
except OSError as e: |
|
app.logger.error('error opening path: %s, %s', path, e.strerror) |
|
return '' |
|
|
|
j = json.load(fd) |
|
fd.close() |
|
|
|
return j['key'] |
|
|
|
|