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.editbooks import editbook
|
||||
from cps.remotelogin import remotelogin
|
||||
from cps.search_metadata import meta
|
||||
from cps.error_handler import init_errorhandler
|
||||
|
||||
try:
|
||||
@ -70,6 +71,7 @@ def main():
|
||||
app.register_blueprint(shelf)
|
||||
app.register_blueprint(admi)
|
||||
app.register_blueprint(remotelogin)
|
||||
app.register_blueprint(meta)
|
||||
# if config.config_use_google_drive:
|
||||
app.register_blueprint(gdrive)
|
||||
app.register_blueprint(editbook)
|
||||
|
@ -26,12 +26,38 @@ class ComicVine(Metadata):
|
||||
__name__ = "ComicVine"
|
||||
|
||||
def search(self, query):
|
||||
val = list()
|
||||
if self.active:
|
||||
headers = {
|
||||
'User-Agent': 'Not Evil Browser' # ,
|
||||
}
|
||||
|
||||
result = requests.get("https://comicvine.gamespot.com/api/search?api_key="
|
||||
+ 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):
|
||||
if self.active:
|
||||
val = list()
|
||||
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"
|
||||
|
||||
def search(self, query):
|
||||
val = list()
|
||||
if self.active:
|
||||
if True:
|
||||
scholar_gen = scholarly.search_pubs(' '.join(query.split('+')))
|
||||
i = 0
|
||||
result = []
|
||||
for publication in scholar_gen:
|
||||
del publication['source']
|
||||
result.append(publication)
|
||||
i += 1
|
||||
if (i >= 10):
|
||||
break
|
||||
return json.dumps(result)
|
||||
return "[]"
|
||||
scholar_gen = scholarly.search_pubs(' '.join(query.split('+')))
|
||||
i = 0
|
||||
for publication in scholar_gen:
|
||||
v = dict()
|
||||
v['id'] = "1234" # publication['bib'].get('title')
|
||||
v['title'] = publication['bib'].get('title')
|
||||
v['authors'] = publication['bib'].get('author', [])
|
||||
v['description'] = publication['bib'].get('abstract', "")
|
||||
v['publisher'] = publication['bib'].get('venue', "")
|
||||
if publication['bib'].get('pub_year'):
|
||||
v['publishedDate'] = publication['bib'].get('pub_year')+"-01-01"
|
||||
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 cps.services.Metadata import Metadata
|
||||
import os
|
||||
import json
|
||||
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, request, Response
|
||||
from flask_login import login_required
|
||||
|
||||
from . import constants, logger
|
||||
@ -28,7 +29,7 @@ from os.path import basename, isfile
|
||||
import importlib
|
||||
import sys, inspect
|
||||
|
||||
opds = Blueprint('metadata', __name__)
|
||||
meta = Blueprint('metadata', __name__)
|
||||
|
||||
log = logger.create()
|
||||
|
||||
@ -54,20 +55,25 @@ def list_classes(provider_list):
|
||||
return classes
|
||||
|
||||
cl = list_classes(new_list)
|
||||
for c in cl:
|
||||
print(c.search("Walking"))
|
||||
#for c in cl:
|
||||
# print(c.search("Walking"))
|
||||
|
||||
@opds.route("/metadata/provider")
|
||||
@meta.route("/metadata/provider")
|
||||
@login_required
|
||||
def metadata_provider():
|
||||
return ""
|
||||
|
||||
@opds.route("/metadata/search")
|
||||
@meta.route("/metadata/search", methods=['POST'])
|
||||
@login_required
|
||||
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
|
||||
def metadata_provider(id):
|
||||
def metadata_replace(id):
|
||||
return ""
|
||||
|
@ -20,7 +20,7 @@
|
||||
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
||||
* ComicVine api document: https://comicvine.gamespot.com/api/documentation
|
||||
*/
|
||||
/* global _, i18nMsg, tinymce */
|
||||
/* global _, i18nMsg, tinymce, getPatch */
|
||||
var dbResults = [];
|
||||
var ggResults = [];
|
||||
var cvResults = [];
|
||||
@ -80,7 +80,7 @@ $(function () {
|
||||
if (showFlag === 1) {
|
||||
$("#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)) &&
|
||||
(cvDone === 3 || (cvDone === 1 && cvResults.length === 0)) &&
|
||||
(gsDone === 3 || (gsDone === 1 && gsResults.length === 0))) {
|
||||
@ -102,6 +102,7 @@ $(function () {
|
||||
|
||||
return [year, month, day].join("-");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -118,8 +119,7 @@ $(function () {
|
||||
publishedDate: result.volumeInfo.publishedDate || "",
|
||||
tags: result.volumeInfo.categories || [],
|
||||
rating: result.volumeInfo.averageRating || 0,
|
||||
cover: result.volumeInfo.imageLinks ?
|
||||
result.volumeInfo.imageLinks.thumbnail : location + "/../../../static/generic_cover.jpg",
|
||||
cover: result.volumeInfo.imageLinks ? result.volumeInfo.imageLinks.thumbnail : location + "/../../../static/generic_cover.jpg",
|
||||
url: "https://books.google.com/books?id=" + result.id,
|
||||
source: {
|
||||
id: "google",
|
||||
@ -277,10 +277,10 @@ $(function () {
|
||||
} else {
|
||||
cvDone = 3;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
function ggSearchBook (title) {
|
||||
/*function ggSearchBook (title) {
|
||||
$.ajax({
|
||||
url: google + ggSearch + "?q=" + title.replace(/\s+/gm, "+"),
|
||||
type: "GET",
|
||||
@ -355,11 +355,38 @@ $(function () {
|
||||
showResult();
|
||||
$("#show-googlescholar").trigger("change");
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
function doSearch (keyword) {
|
||||
showFlag = 0;
|
||||
function doSearch (keyword) {
|
||||
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;
|
||||
dbResults = [];
|
||||
ggResults = [];
|
||||
@ -371,23 +398,21 @@ $(function () {
|
||||
ggSearchBook(keyword);
|
||||
cvSearchBook(keyword);
|
||||
gsSearchBook(keyword);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
$("#meta-search").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
var keyword = $("#keyword").val();
|
||||
if (keyword) {
|
||||
doSearch(keyword);
|
||||
}
|
||||
});
|
||||
|
||||
$("#get_meta").click(function () {
|
||||
var bookTitle = $("#book_title").val();
|
||||
if (bookTitle) {
|
||||
$("#keyword").val(bookTitle);
|
||||
doSearch(bookTitle);
|
||||
}
|
||||
});
|
||||
$("#meta-search").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
var keyword = $("#keyword").val();
|
||||
doSearch(keyword);
|
||||
});
|
||||
|
||||
$("#get_meta").click(function () {
|
||||
var bookTitle = $("#book_title").val();
|
||||
if (bookTitle) {
|
||||
$("#keyword").val(bookTitle);
|
||||
doSearch(bookTitle);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -259,7 +259,7 @@
|
||||
<div id="meta-info">
|
||||
{{_("Loading...")}}
|
||||
</div>
|
||||
<ul id="book-list" class="media-list"></ul>
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user