Update python search Metadata

This commit is contained in:
Ozzie Isaacs 2021-07-08 19:14:38 +02:00
parent aa2d3d2b36
commit ec7803fa76
6 changed files with 52 additions and 21 deletions

View File

@ -21,13 +21,14 @@
import requests
from cps.services.Metadata import Metadata
apikey = "57558043c53943d5d1e96a9ad425b0eb85532ee6"
class ComicVine(Metadata):
__name__ = "ComicVine"
__id__ = "comicvine"
def search(self, query):
val = list()
apikey = "57558043c53943d5d1e96a9ad425b0eb85532ee6"
if self.active:
headers = {
'User-Agent': 'Not Evil Browser' # ,
@ -53,7 +54,7 @@ class ComicVine(Metadata):
v['series'] = seriesTitle
v['cover'] = r['image'].get('original_url')
v['source'] = {
"id": "comicvine",
"id": self.__id__,
"description": "ComicVine Books",
"link": "https://comicvine.gamespot.com/"
}

View File

@ -24,6 +24,7 @@ from cps.services.Metadata import Metadata
class Google(Metadata):
__name__ = "Google"
__id__ = "google"
def search(self, query):
if self.active:
@ -44,7 +45,7 @@ class Google(Metadata):
else:
v['cover'] = "/../../../static/generic_cover.jpg"
v['source'] = {
"id": "google",
"id": self.__id__,
"description": "Google Books",
"link": "https://books.google.com/"}
v['url'] = ""

View File

@ -29,7 +29,8 @@ from cps.services.Metadata import Metadata
class scholar(Metadata):
__name__ = "ComicVine"
__name__ = "Google Scholar"
__id__ = "googlescholar"
def search(self, query):
val = list()
@ -53,7 +54,7 @@ class scholar(Metadata):
v['cover'] = "/../../../static/generic_cover.jpg"
v['url'] = ""
v['source'] = {
"id": "googlescholar",
"id": self.__id__,
"description": "Google Scholar",
"link": "https://scholar.google.com/"
}

View File

@ -24,6 +24,7 @@ import sys
import inspect
from flask import Blueprint, request, Response
from flask_login import current_user
from flask_login import login_required
from . import constants, logger
@ -59,14 +60,29 @@ cl = list_classes(new_list)
@meta.route("/metadata/provider")
@login_required
def metadata_provider():
return ""
active = current_user.view_settings.get('metadata', {})
provider = list()
for c in cl:
provider.append({"name": c.__name__, "active": active.get(c.__name__, True), "id": c.__id__})
return Response(json.dumps(provider), mimetype='application/json')
@meta.route("/metadata/provider", methods=['POST'])
@login_required
def metadata_change_active_provider():
active = current_user.view_settings.get('metadata', {})
provider = list()
for c in cl:
provider.append({"name": c.__name__, "active": active.get(c.__name__, True), "id": c.__id__})
return Response(json.dumps(provider), mimetype='application/json')
@meta.route("/metadata/search", methods=['POST'])
@login_required
def metadata_search():
query = request.form.to_dict().get('query')
data = list()
active = current_user.view_settings.get('metadata', {})
if query:
for c in cl:
data.extend(c.search(query))
if active.get(c.__name__, True):
data.extend(c.search(query))
return Response(json.dumps(data), mimetype='application/json')

View File

@ -73,6 +73,28 @@ $(function () {
}
}
function populate_provider() {
$("#metadata_provider").empty();
$.ajax({
url: getPath() + "/metadata/provider",
type: "get",
dataType: "json",
success: function success(data) {
console.log(data);
data.forEach(function(provider) {
//$("#metadata_provider").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
var checked = "";
if (provider.active) {
checked = "checked";
}
var $provider_button = '<input type="checkbox" id="show-' + provider.name + '" class="pill" data-control="' + provider.id + '" ' + checked + '><label for="show-' + provider.name + '">' + provider.name + ' <span class="glyphicon glyphicon-ok"></span></label>'
$("#metadata_provider").append($provider_button);
});
},
});
}
$("#meta-search").on("submit", function (e) {
e.preventDefault();
var keyword = $("#keyword").val();
@ -80,10 +102,9 @@ $(function () {
});
$("#get_meta").click(function () {
populate_provider();
var bookTitle = $("#book_title").val();
if (bookTitle) {
$("#keyword").val(bookTitle);
doSearch(bookTitle);
}
$("#keyword").val(bookTitle);
doSearch(bookTitle);
});
});

View File

@ -241,21 +241,12 @@
<div class="text-center"><strong>{{_('Click the cover to load metadata to the form')}}</strong></div>
</div>
<div class="modal-body">
<div class="text-center padded-bottom">
<input type="checkbox" id="show-google" class="pill" data-control="google" checked>
<label for="show-google">Google <span class="glyphicon glyphicon-ok"></span></label>
<input type="checkbox" id="show-comics" class="pill" data-control="comicvine" checked>
<label for="show-comics">ComicVine <span class="glyphicon glyphicon-ok"></span></label>
<input type="checkbox" id="show-googlescholar" class="pill" data-control="googlescholar" checked>
<label for="show-googlescholar">Google Scholar <span class="glyphicon glyphicon-ok"></span></label>
<div class="text-center padded-bottom" id="metadata_provider">
</div>
<div id="meta-info">
{{_("Loading...")}}
</div>
<!--ul id="book-list" class="media-list"></ul-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{_('Close')}}</button>