Update python search Metadata
This commit is contained in:
parent
aa2d3d2b36
commit
ec7803fa76
|
@ -21,13 +21,14 @@
|
||||||
import requests
|
import requests
|
||||||
from cps.services.Metadata import Metadata
|
from cps.services.Metadata import Metadata
|
||||||
|
|
||||||
apikey = "57558043c53943d5d1e96a9ad425b0eb85532ee6"
|
|
||||||
|
|
||||||
class ComicVine(Metadata):
|
class ComicVine(Metadata):
|
||||||
__name__ = "ComicVine"
|
__name__ = "ComicVine"
|
||||||
|
__id__ = "comicvine"
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
val = list()
|
val = list()
|
||||||
|
apikey = "57558043c53943d5d1e96a9ad425b0eb85532ee6"
|
||||||
if self.active:
|
if self.active:
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'Not Evil Browser' # ,
|
'User-Agent': 'Not Evil Browser' # ,
|
||||||
|
@ -53,7 +54,7 @@ class ComicVine(Metadata):
|
||||||
v['series'] = seriesTitle
|
v['series'] = seriesTitle
|
||||||
v['cover'] = r['image'].get('original_url')
|
v['cover'] = r['image'].get('original_url')
|
||||||
v['source'] = {
|
v['source'] = {
|
||||||
"id": "comicvine",
|
"id": self.__id__,
|
||||||
"description": "ComicVine Books",
|
"description": "ComicVine Books",
|
||||||
"link": "https://comicvine.gamespot.com/"
|
"link": "https://comicvine.gamespot.com/"
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ from cps.services.Metadata import Metadata
|
||||||
|
|
||||||
class Google(Metadata):
|
class Google(Metadata):
|
||||||
__name__ = "Google"
|
__name__ = "Google"
|
||||||
|
__id__ = "google"
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
if self.active:
|
if self.active:
|
||||||
|
@ -44,7 +45,7 @@ class Google(Metadata):
|
||||||
else:
|
else:
|
||||||
v['cover'] = "/../../../static/generic_cover.jpg"
|
v['cover'] = "/../../../static/generic_cover.jpg"
|
||||||
v['source'] = {
|
v['source'] = {
|
||||||
"id": "google",
|
"id": self.__id__,
|
||||||
"description": "Google Books",
|
"description": "Google Books",
|
||||||
"link": "https://books.google.com/"}
|
"link": "https://books.google.com/"}
|
||||||
v['url'] = ""
|
v['url'] = ""
|
||||||
|
|
|
@ -29,7 +29,8 @@ from cps.services.Metadata import Metadata
|
||||||
|
|
||||||
|
|
||||||
class scholar(Metadata):
|
class scholar(Metadata):
|
||||||
__name__ = "ComicVine"
|
__name__ = "Google Scholar"
|
||||||
|
__id__ = "googlescholar"
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
val = list()
|
val = list()
|
||||||
|
@ -53,7 +54,7 @@ class scholar(Metadata):
|
||||||
v['cover'] = "/../../../static/generic_cover.jpg"
|
v['cover'] = "/../../../static/generic_cover.jpg"
|
||||||
v['url'] = ""
|
v['url'] = ""
|
||||||
v['source'] = {
|
v['source'] = {
|
||||||
"id": "googlescholar",
|
"id": self.__id__,
|
||||||
"description": "Google Scholar",
|
"description": "Google Scholar",
|
||||||
"link": "https://scholar.google.com/"
|
"link": "https://scholar.google.com/"
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import sys
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from flask import Blueprint, request, Response
|
from flask import Blueprint, request, Response
|
||||||
|
from flask_login import current_user
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from . import constants, logger
|
from . import constants, logger
|
||||||
|
@ -59,14 +60,29 @@ cl = list_classes(new_list)
|
||||||
@meta.route("/metadata/provider")
|
@meta.route("/metadata/provider")
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_provider():
|
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'])
|
@meta.route("/metadata/search", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_search():
|
def metadata_search():
|
||||||
query = request.form.to_dict().get('query')
|
query = request.form.to_dict().get('query')
|
||||||
data = list()
|
data = list()
|
||||||
|
active = current_user.view_settings.get('metadata', {})
|
||||||
if query:
|
if query:
|
||||||
for c in cl:
|
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')
|
return Response(json.dumps(data), mimetype='application/json')
|
||||||
|
|
|
@ -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) {
|
$("#meta-search").on("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var keyword = $("#keyword").val();
|
var keyword = $("#keyword").val();
|
||||||
|
@ -80,10 +102,9 @@ $(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#get_meta").click(function () {
|
$("#get_meta").click(function () {
|
||||||
|
populate_provider();
|
||||||
var bookTitle = $("#book_title").val();
|
var bookTitle = $("#book_title").val();
|
||||||
if (bookTitle) {
|
$("#keyword").val(bookTitle);
|
||||||
$("#keyword").val(bookTitle);
|
doSearch(bookTitle);
|
||||||
doSearch(bookTitle);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -241,21 +241,12 @@
|
||||||
<div class="text-center"><strong>{{_('Click the cover to load metadata to the form')}}</strong></div>
|
<div class="text-center"><strong>{{_('Click the cover to load metadata to the form')}}</strong></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="text-center padded-bottom">
|
<div class="text-center padded-bottom" id="metadata_provider">
|
||||||
<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>
|
</div>
|
||||||
|
|
||||||
<div id="meta-info">
|
<div id="meta-info">
|
||||||
{{_("Loading...")}}
|
{{_("Loading...")}}
|
||||||
</div>
|
</div>
|
||||||
<!--ul id="book-list" class="media-list"></ul-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{_('Close')}}</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">{{_('Close')}}</button>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user