mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Optimisation of nicebooks covers
This commit is contained in:
parent
4887bac205
commit
3490c73ad9
@ -266,7 +266,7 @@ class ResultList(list):
|
|||||||
|
|
||||||
def populate(self, entries, browser, verbose=False):
|
def populate(self, entries, browser, verbose=False):
|
||||||
#single entry
|
#single entry
|
||||||
if len(entries) ==1:
|
if len(entries) == 1 and not isinstance(entries[0], str):
|
||||||
try:
|
try:
|
||||||
entry = entries[0].xpath("//div[@id='container']")[0]
|
entry = entries[0].xpath("//div[@id='container']")[0]
|
||||||
entry = entry.find("div[@id='book-info']")
|
entry = entry.find("div[@id='book-info']")
|
||||||
@ -314,25 +314,20 @@ class Covers(object):
|
|||||||
except:
|
except:
|
||||||
return self
|
return self
|
||||||
isbno = entry.get_element_by_id('book-info').find("dl[@title='Informations sur le livre']")
|
isbno = entry.get_element_by_id('book-info').find("dl[@title='Informations sur le livre']")
|
||||||
isbntext = None
|
|
||||||
for x in isbno.getiterator('dt'):
|
for x in isbno.getiterator('dt'):
|
||||||
if x.text == 'ISBN':
|
if x.text == 'ISBN' and check_isbn(x.getnext().text_content()):
|
||||||
isbntext = x.getnext().text_content()
|
|
||||||
break
|
|
||||||
if isbntext is not None:
|
|
||||||
self.isbnf = True
|
self.isbnf = True
|
||||||
|
break
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def check_cover(self):
|
def check_cover(self):
|
||||||
if self.urlimg:
|
return True if self.urlimg else False
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_cover(self, browser, timeout = 5.):
|
def get_cover(self, browser, timeout = 5.):
|
||||||
try:
|
try:
|
||||||
return browser.open_novisit(self.urlimg, timeout=timeout).read(), \
|
cover, ext = browser.open_novisit(self.urlimg, timeout=timeout).read(), \
|
||||||
self.urlimg.rpartition('.')[-1]
|
self.urlimg.rpartition('.')[-1]
|
||||||
|
return cover, ext if ext else 'jpg'
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
if isinstance(getattr(err, 'args', [None])[0], socket.timeout):
|
||||||
err = NiceBooksError(_('Nicebooks timed out. Try again later.'))
|
err = NiceBooksError(_('Nicebooks timed out. Try again later.'))
|
||||||
@ -417,8 +412,6 @@ def main(args=sys.argv):
|
|||||||
print textcover
|
print textcover
|
||||||
elif covact == 2:
|
elif covact == 2:
|
||||||
cover_data, ext = cover_from_isbn(result.isbn)
|
cover_data, ext = cover_from_isbn(result.isbn)
|
||||||
if not ext:
|
|
||||||
ext = 'jpg'
|
|
||||||
cpath = result.isbn
|
cpath = result.isbn
|
||||||
if len(opts.coverspath):
|
if len(opts.coverspath):
|
||||||
cpath = os.path.normpath(opts.coverspath + '/' + result.isbn)
|
cpath = os.path.normpath(opts.coverspath + '/' + result.isbn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user