mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 01:20:32 +00:00
Search Metadata improvements
This commit is contained in:
parent
0d247fef6a
commit
d5e9cdc5b7
2
cps.py
2
cps.py
@ -42,6 +42,7 @@ from cps.admin import admi
|
|||||||
from cps.gdrive import gdrive
|
from cps.gdrive import gdrive
|
||||||
from cps.editbooks import editbook
|
from cps.editbooks import editbook
|
||||||
from cps.remotelogin import remotelogin
|
from cps.remotelogin import remotelogin
|
||||||
|
from cps.search_metadata import meta
|
||||||
from cps.error_handler import init_errorhandler
|
from cps.error_handler import init_errorhandler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -70,6 +71,7 @@ def main():
|
|||||||
app.register_blueprint(shelf)
|
app.register_blueprint(shelf)
|
||||||
app.register_blueprint(admi)
|
app.register_blueprint(admi)
|
||||||
app.register_blueprint(remotelogin)
|
app.register_blueprint(remotelogin)
|
||||||
|
app.register_blueprint(meta)
|
||||||
# if config.config_use_google_drive:
|
# if config.config_use_google_drive:
|
||||||
app.register_blueprint(gdrive)
|
app.register_blueprint(gdrive)
|
||||||
app.register_blueprint(editbook)
|
app.register_blueprint(editbook)
|
||||||
|
@ -26,12 +26,38 @@ class ComicVine(Metadata):
|
|||||||
__name__ = "ComicVine"
|
__name__ = "ComicVine"
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
|
val = list()
|
||||||
if self.active:
|
if self.active:
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'Not Evil Browser' # ,
|
'User-Agent': 'Not Evil Browser' # ,
|
||||||
}
|
}
|
||||||
|
|
||||||
result = requests.get("https://comicvine.gamespot.com/api/search?api_key="
|
result = requests.get("https://comicvine.gamespot.com/api/search?api_key="
|
||||||
+ apikey + "&resources=issue&query=" + query + "&sort=name:desc&format=json", headers=headers)
|
+ apikey + "&resources=issue&query=" + query + "&sort=name:desc&format=json", headers=headers)
|
||||||
return [result.json()['results']]
|
for r in result.json()['results']:
|
||||||
|
seriesTitle = r['volume'].get('name', "")
|
||||||
|
if r.get('store_date'):
|
||||||
|
dateFomers = r.get('store_date')
|
||||||
|
else:
|
||||||
|
dateFomers = r.get('date_added')
|
||||||
|
v = dict()
|
||||||
|
v['id'] = r['id']
|
||||||
|
v['title'] = seriesTitle + " #" + r.get('issue_number', "0") + " - " + ( r.get('name', "") or "")
|
||||||
|
v['authors'] = r.get('authors', [])
|
||||||
|
v['description'] = r.get('description', "")
|
||||||
|
v['publisher'] = ""
|
||||||
|
v['publishedDate'] = dateFomers
|
||||||
|
v['tags'] = ["Comics", seriesTitle]
|
||||||
|
v['rating'] = 0
|
||||||
|
v['series'] = seriesTitle
|
||||||
|
v['cover'] = r['image'].get('original_url')
|
||||||
|
v['source'] = {
|
||||||
|
"id": "comicvine",
|
||||||
|
"description": "ComicVine Books",
|
||||||
|
"link": "https://comicvine.gamespot.com/"
|
||||||
|
}
|
||||||
|
v['url'] = ""
|
||||||
|
val.append(v)
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,28 @@ class Google(Metadata):
|
|||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
if self.active:
|
if self.active:
|
||||||
|
val = list()
|
||||||
result = requests.get("https://www.googleapis.com/books/v1/volumes?q="+query.replace(" ","+"))
|
result = requests.get("https://www.googleapis.com/books/v1/volumes?q="+query.replace(" ","+"))
|
||||||
return [result.json()['items']]
|
for r in result.json()['items']:
|
||||||
|
v = dict()
|
||||||
|
v['id'] = r['id']
|
||||||
|
v['title'] = r['volumeInfo']['title']
|
||||||
|
v['authors'] = r['volumeInfo'].get('authors', [])
|
||||||
|
v['description'] = r['volumeInfo'].get('description', "")
|
||||||
|
v['publisher'] = r['volumeInfo'].get('publisher', "")
|
||||||
|
v['publishedDate'] = r['volumeInfo'].get('publishedDate', "")
|
||||||
|
v['tags'] = r['volumeInfo'].get('categories', [])
|
||||||
|
v['rating'] = r['volumeInfo'].get('averageRating', 0)
|
||||||
|
if r['volumeInfo'].get('imageLinks'):
|
||||||
|
v['cover'] = r['volumeInfo']['imageLinks']['thumbnail']
|
||||||
|
else:
|
||||||
|
v['cover'] = "/../../../static/generic_cover.jpg"
|
||||||
|
v['source'] = {
|
||||||
|
"id": "google",
|
||||||
|
"description": "Google Books",
|
||||||
|
"link": "https://books.google.com/"}
|
||||||
|
v['url'] = ""
|
||||||
|
val.append(v)
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,19 +32,36 @@ class scholar(Metadata):
|
|||||||
__name__ = "ComicVine"
|
__name__ = "ComicVine"
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
|
val = list()
|
||||||
if self.active:
|
if self.active:
|
||||||
if True:
|
scholar_gen = scholarly.search_pubs(' '.join(query.split('+')))
|
||||||
scholar_gen = scholarly.search_pubs(' '.join(query.split('+')))
|
i = 0
|
||||||
i = 0
|
for publication in scholar_gen:
|
||||||
result = []
|
v = dict()
|
||||||
for publication in scholar_gen:
|
v['id'] = "1234" # publication['bib'].get('title')
|
||||||
del publication['source']
|
v['title'] = publication['bib'].get('title')
|
||||||
result.append(publication)
|
v['authors'] = publication['bib'].get('author', [])
|
||||||
i += 1
|
v['description'] = publication['bib'].get('abstract', "")
|
||||||
if (i >= 10):
|
v['publisher'] = publication['bib'].get('venue', "")
|
||||||
break
|
if publication['bib'].get('pub_year'):
|
||||||
return json.dumps(result)
|
v['publishedDate'] = publication['bib'].get('pub_year')+"-01-01"
|
||||||
return "[]"
|
else:
|
||||||
|
v['publishedDate'] = ""
|
||||||
|
v['tags'] = ""
|
||||||
|
v['ratings'] = 0
|
||||||
|
v['series'] = ""
|
||||||
|
v['cover'] = "/../../../static/generic_cover.jpg"
|
||||||
|
v['url'] = ""
|
||||||
|
v['source'] = {
|
||||||
|
"id": "googlescholar",
|
||||||
|
"description": "Google Scholar",
|
||||||
|
"link": "https://scholar.google.com/"
|
||||||
|
}
|
||||||
|
val.append(v)
|
||||||
|
i += 1
|
||||||
|
if (i >= 10):
|
||||||
|
break
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
from __future__ import division, print_function, unicode_literals
|
from __future__ import division, print_function, unicode_literals
|
||||||
from cps.services.Metadata import Metadata
|
from cps.services.Metadata import Metadata
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import Blueprint
|
from flask import Blueprint, request, Response
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from . import constants, logger
|
from . import constants, logger
|
||||||
@ -28,7 +29,7 @@ from os.path import basename, isfile
|
|||||||
import importlib
|
import importlib
|
||||||
import sys, inspect
|
import sys, inspect
|
||||||
|
|
||||||
opds = Blueprint('metadata', __name__)
|
meta = Blueprint('metadata', __name__)
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
|
|
||||||
@ -54,20 +55,25 @@ def list_classes(provider_list):
|
|||||||
return classes
|
return classes
|
||||||
|
|
||||||
cl = list_classes(new_list)
|
cl = list_classes(new_list)
|
||||||
for c in cl:
|
#for c in cl:
|
||||||
print(c.search("Walking"))
|
# print(c.search("Walking"))
|
||||||
|
|
||||||
@opds.route("/metadata/provider")
|
@meta.route("/metadata/provider")
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_provider():
|
def metadata_provider():
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@opds.route("/metadata/search")
|
@meta.route("/metadata/search", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_search():
|
def metadata_search():
|
||||||
return ""
|
query = request.form.to_dict().get('query')
|
||||||
|
data = list()
|
||||||
|
if query:
|
||||||
|
for c in cl:
|
||||||
|
data.extend(c.search(query))
|
||||||
|
return Response(json.dumps(data), mimetype='application/json')
|
||||||
|
|
||||||
@opds.route("/metadata/replace/<id>")
|
@meta.route("/metadata/replace/<id>")
|
||||||
@login_required
|
@login_required
|
||||||
def metadata_provider(id):
|
def metadata_replace(id):
|
||||||
return ""
|
return ""
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
||||||
* ComicVine api document: https://comicvine.gamespot.com/api/documentation
|
* ComicVine api document: https://comicvine.gamespot.com/api/documentation
|
||||||
*/
|
*/
|
||||||
/* global _, i18nMsg, tinymce */
|
/* global _, i18nMsg, tinymce, getPatch */
|
||||||
var dbResults = [];
|
var dbResults = [];
|
||||||
var ggResults = [];
|
var ggResults = [];
|
||||||
var cvResults = [];
|
var cvResults = [];
|
||||||
@ -80,7 +80,7 @@ $(function () {
|
|||||||
if (showFlag === 1) {
|
if (showFlag === 1) {
|
||||||
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
||||||
}
|
}
|
||||||
if ((ggDone === 3 || (ggDone === 1 && ggResults.length === 0)) &&
|
/*if ((ggDone === 3 || (ggDone === 1 && ggResults.length === 0)) &&
|
||||||
(dbDone === 3 || (dbDone === 1 && dbResults.length === 0)) &&
|
(dbDone === 3 || (dbDone === 1 && dbResults.length === 0)) &&
|
||||||
(cvDone === 3 || (cvDone === 1 && cvResults.length === 0)) &&
|
(cvDone === 3 || (cvDone === 1 && cvResults.length === 0)) &&
|
||||||
(gsDone === 3 || (gsDone === 1 && gsResults.length === 0))) {
|
(gsDone === 3 || (gsDone === 1 && gsResults.length === 0))) {
|
||||||
@ -102,6 +102,7 @@ $(function () {
|
|||||||
|
|
||||||
return [year, month, day].join("-");
|
return [year, month, day].join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateID (title) {
|
function generateID (title) {
|
||||||
return title.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0).toString().substr(0,12);
|
return title.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0).toString().substr(0,12);
|
||||||
}
|
}
|
||||||
@ -118,8 +119,7 @@ $(function () {
|
|||||||
publishedDate: result.volumeInfo.publishedDate || "",
|
publishedDate: result.volumeInfo.publishedDate || "",
|
||||||
tags: result.volumeInfo.categories || [],
|
tags: result.volumeInfo.categories || [],
|
||||||
rating: result.volumeInfo.averageRating || 0,
|
rating: result.volumeInfo.averageRating || 0,
|
||||||
cover: result.volumeInfo.imageLinks ?
|
cover: result.volumeInfo.imageLinks ? result.volumeInfo.imageLinks.thumbnail : location + "/../../../static/generic_cover.jpg",
|
||||||
result.volumeInfo.imageLinks.thumbnail : location + "/../../../static/generic_cover.jpg",
|
|
||||||
url: "https://books.google.com/books?id=" + result.id,
|
url: "https://books.google.com/books?id=" + result.id,
|
||||||
source: {
|
source: {
|
||||||
id: "google",
|
id: "google",
|
||||||
@ -277,10 +277,10 @@ $(function () {
|
|||||||
} else {
|
} else {
|
||||||
cvDone = 3;
|
cvDone = 3;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
function ggSearchBook (title) {
|
/*function ggSearchBook (title) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: google + ggSearch + "?q=" + title.replace(/\s+/gm, "+"),
|
url: google + ggSearch + "?q=" + title.replace(/\s+/gm, "+"),
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@ -355,11 +355,38 @@ $(function () {
|
|||||||
showResult();
|
showResult();
|
||||||
$("#show-googlescholar").trigger("change");
|
$("#show-googlescholar").trigger("change");
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}*/
|
||||||
|
|
||||||
function doSearch (keyword) {
|
function doSearch (keyword) {
|
||||||
showFlag = 0;
|
if (keyword) {
|
||||||
|
$("#meta-info").text(msg.loading);
|
||||||
|
$.ajax({
|
||||||
|
url: getPath() + "/metadata/search",
|
||||||
|
type: "POST",
|
||||||
|
data: {"query": keyword},
|
||||||
|
dataType: "json",
|
||||||
|
success: function success(data) {
|
||||||
|
console.log(data);
|
||||||
|
data.forEach(function(book) {
|
||||||
|
var $book = $(templates.bookResult(book));
|
||||||
|
$book.find("img").on("click", function () {
|
||||||
|
populateForm(book);
|
||||||
|
});
|
||||||
|
$("#book-list").append($book);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function error() {
|
||||||
|
$("#meta-info").html("<p class=\"text-danger\">" + msg.search_error + "!</p>" + $("#meta-info")[0].innerHTML);
|
||||||
|
},
|
||||||
|
complete: function complete() {
|
||||||
|
showResult();
|
||||||
|
// $("#show-douban").trigger("change");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*showFlag = 0;
|
||||||
dbDone = ggDone = cvDone = 0;
|
dbDone = ggDone = cvDone = 0;
|
||||||
dbResults = [];
|
dbResults = [];
|
||||||
ggResults = [];
|
ggResults = [];
|
||||||
@ -371,23 +398,21 @@ $(function () {
|
|||||||
ggSearchBook(keyword);
|
ggSearchBook(keyword);
|
||||||
cvSearchBook(keyword);
|
cvSearchBook(keyword);
|
||||||
gsSearchBook(keyword);
|
gsSearchBook(keyword);
|
||||||
}
|
}*/
|
||||||
}
|
|
||||||
|
|
||||||
$("#meta-search").on("submit", function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var keyword = $("#keyword").val();
|
|
||||||
if (keyword) {
|
|
||||||
doSearch(keyword);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#get_meta").click(function () {
|
$("#meta-search").on("submit", function (e) {
|
||||||
var bookTitle = $("#book_title").val();
|
e.preventDefault();
|
||||||
if (bookTitle) {
|
var keyword = $("#keyword").val();
|
||||||
$("#keyword").val(bookTitle);
|
doSearch(keyword);
|
||||||
doSearch(bookTitle);
|
});
|
||||||
}
|
|
||||||
});
|
$("#get_meta").click(function () {
|
||||||
|
var bookTitle = $("#book_title").val();
|
||||||
|
if (bookTitle) {
|
||||||
|
$("#keyword").val(bookTitle);
|
||||||
|
doSearch(bookTitle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -259,7 +259,7 @@
|
|||||||
<div id="meta-info">
|
<div id="meta-info">
|
||||||
{{_("Loading...")}}
|
{{_("Loading...")}}
|
||||||
</div>
|
</div>
|
||||||
<ul id="book-list" class="media-list"></ul>
|
<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