2021-07-05 09:55:54 -07:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2021 OzzieIsaacs
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
2021-07-06 11:24:27 -07:00
|
|
|
from cps.services.Metadata import Metadata
|
2021-07-05 09:55:54 -07:00
|
|
|
import os
|
|
|
|
|
2021-07-06 11:24:27 -07:00
|
|
|
from flask import Blueprint
|
2021-07-05 09:55:54 -07:00
|
|
|
from flask_login import login_required
|
|
|
|
|
2021-07-06 11:24:27 -07:00
|
|
|
from . import constants, logger
|
|
|
|
from os.path import basename, isfile
|
|
|
|
import importlib
|
|
|
|
import sys, inspect
|
2021-07-05 09:55:54 -07:00
|
|
|
|
|
|
|
opds = Blueprint('metadata', __name__)
|
|
|
|
|
|
|
|
log = logger.create()
|
|
|
|
|
2021-07-06 11:24:27 -07:00
|
|
|
new_list = list()
|
2021-07-05 09:55:54 -07:00
|
|
|
meta_dir = os.path.join(constants.BASE_DIR, "cps", "metadata_provider")
|
|
|
|
modules = os.listdir(os.path.join(constants.BASE_DIR, "cps", "metadata_provider")) #glob.glob(join(dirname(__file__), "*.py"))
|
2021-07-06 11:24:27 -07:00
|
|
|
for f in modules:
|
|
|
|
if isfile(os.path.join(meta_dir, f)) and not f.endswith('__init__.py'):
|
|
|
|
a = basename(f)[:-3]
|
|
|
|
try:
|
|
|
|
importlib.import_module("cps.metadata_provider." + a)
|
|
|
|
new_list.append(a)
|
|
|
|
except ImportError:
|
|
|
|
log.error("Import error for metadata source: {}".format(a))
|
|
|
|
pass
|
2021-07-05 09:55:54 -07:00
|
|
|
|
2021-07-06 11:24:27 -07:00
|
|
|
def list_classes(provider_list):
|
|
|
|
classes = list()
|
|
|
|
for element in provider_list:
|
|
|
|
for name, obj in inspect.getmembers(sys.modules["cps.metadata_provider." + element]):
|
|
|
|
if inspect.isclass(obj) and name != "Metadata" and issubclass(obj, Metadata):
|
|
|
|
classes.append(obj())
|
|
|
|
return classes
|
2021-07-05 09:55:54 -07:00
|
|
|
|
2021-07-06 11:24:27 -07:00
|
|
|
cl = list_classes(new_list)
|
|
|
|
for c in cl:
|
|
|
|
print(c.search("Walking"))
|
2021-07-05 09:55:54 -07:00
|
|
|
|
|
|
|
@opds.route("/metadata/provider")
|
|
|
|
@login_required
|
|
|
|
def metadata_provider():
|
|
|
|
return ""
|
|
|
|
|
|
|
|
@opds.route("/metadata/search")
|
|
|
|
@login_required
|
|
|
|
def metadata_search():
|
|
|
|
return ""
|
|
|
|
|
|
|
|
@opds.route("/metadata/replace/<id>")
|
|
|
|
@login_required
|
|
|
|
def metadata_provider(id):
|
|
|
|
return ""
|