mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
import modifications
This commit is contained in:
parent
c6fab3c849
commit
6ca1bf64ef
@ -172,23 +172,6 @@ class MetadataSource(Plugin): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# class GoogleBooks(MetadataSource): # {{{
|
|
||||||
|
|
||||||
# name = 'Google Books'
|
|
||||||
# description = _('Downloads metadata from Google Books')
|
|
||||||
|
|
||||||
# def fetch(self):
|
|
||||||
# from calibre.ebooks.metadata.google_books import search
|
|
||||||
# try:
|
|
||||||
# self.results = search(self.title, self.book_author, self.publisher,
|
|
||||||
# self.isbn, max_results=10,
|
|
||||||
# verbose=self.verbose)
|
|
||||||
# except Exception, e:
|
|
||||||
# self.exception = e
|
|
||||||
# self.tb = traceback.format_exc()
|
|
||||||
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
class ISBNDB(MetadataSource): # {{{
|
class ISBNDB(MetadataSource): # {{{
|
||||||
|
|
||||||
name = 'IsbnDB'
|
name = 'IsbnDB'
|
||||||
@ -226,27 +209,6 @@ class ISBNDB(MetadataSource): # {{{
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# class Amazon(MetadataSource): # {{{
|
|
||||||
|
|
||||||
# name = 'Amazon'
|
|
||||||
# metadata_type = 'social'
|
|
||||||
# description = _('Downloads social metadata from amazon.com')
|
|
||||||
|
|
||||||
# has_html_comments = True
|
|
||||||
|
|
||||||
# def fetch(self):
|
|
||||||
# if not self.isbn:
|
|
||||||
# return
|
|
||||||
# from calibre.ebooks.metadata.amazon import get_social_metadata
|
|
||||||
# try:
|
|
||||||
# self.results = get_social_metadata(self.title, self.book_author,
|
|
||||||
# self.publisher, self.isbn)
|
|
||||||
# except Exception, e:
|
|
||||||
# self.exception = e
|
|
||||||
# self.tb = traceback.format_exc()
|
|
||||||
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
class LibraryThing(MetadataSource): # {{{
|
class LibraryThing(MetadataSource): # {{{
|
||||||
|
|
||||||
name = 'LibraryThing'
|
name = 'LibraryThing'
|
||||||
|
@ -3,7 +3,7 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2010, sengian <sengian1@gmail.com>'
|
__copyright__ = '2010, sengian <sengian1@gmail.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys, textwrap, re, traceback, socket
|
import sys, re
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
@ -32,6 +32,7 @@ class Fictionwise(MetadataSource):
|
|||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose)
|
self.isbn, max_results=10, verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import traceback
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ class ThreadwithResults(Thread):
|
|||||||
|
|
||||||
def report(verbose):
|
def report(verbose):
|
||||||
if verbose:
|
if verbose:
|
||||||
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
@ -108,11 +110,12 @@ class Query(object):
|
|||||||
|
|
||||||
def __call__(self, browser, verbose, timeout = 5.):
|
def __call__(self, browser, verbose, timeout = 5.):
|
||||||
if verbose:
|
if verbose:
|
||||||
print _('Query: %s') % self.BASE_URL+self.urldata
|
print _('Query: %s POST: %s') % (self.BASE_URL, self.urldata)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(self.BASE_URL, self.urldata, timeout=timeout).read()
|
raw = browser.open_novisit(self.BASE_URL, self.urldata, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import socket
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -321,6 +324,7 @@ class ResultList(list):
|
|||||||
try:
|
try:
|
||||||
raw = br.open_novisit(url).read()
|
raw = br.open_novisit(url).read()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import socket
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -410,6 +414,7 @@ def search(title=None, author=None, publisher=None, isbn=None,
|
|||||||
|
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
|
import textwrap
|
||||||
parser = OptionParser(textwrap.dedent(\
|
parser = OptionParser(textwrap.dedent(\
|
||||||
_('''\
|
_('''\
|
||||||
%prog [options]
|
%prog [options]
|
||||||
|
@ -3,7 +3,7 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys, textwrap, traceback, socket
|
import sys
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
@ -53,6 +53,7 @@ class GoogleBooks(MetadataSource):
|
|||||||
self.results = search(self.title, self.book_author, self.publisher,
|
self.results = search(self.title, self.book_author, self.publisher,
|
||||||
self.isbn, max_results=10, verbose=self.verbose)
|
self.isbn, max_results=10, verbose=self.verbose)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import traceback
|
||||||
self.exception = e
|
self.exception = e
|
||||||
self.tb = traceback.format_exc()
|
self.tb = traceback.format_exc()
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ class ThreadwithResults(Thread):
|
|||||||
|
|
||||||
def report(verbose):
|
def report(verbose):
|
||||||
if verbose:
|
if verbose:
|
||||||
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
@ -89,6 +91,7 @@ class Query(object):
|
|||||||
isbn is None)
|
isbn is None)
|
||||||
assert (max_results < 41)
|
assert (max_results < 41)
|
||||||
assert (min_viewability in ('none', 'partial', 'full'))
|
assert (min_viewability in ('none', 'partial', 'full'))
|
||||||
|
|
||||||
if title == _('Unknown'):
|
if title == _('Unknown'):
|
||||||
title=None
|
title=None
|
||||||
if author == _('Unknown'):
|
if author == _('Unknown'):
|
||||||
@ -125,6 +128,7 @@ class Query(object):
|
|||||||
try:
|
try:
|
||||||
raw = browser.open_novisit(url, timeout=timeout).read()
|
raw = browser.open_novisit(url, timeout=timeout).read()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import socket
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -271,6 +275,7 @@ class ResultList(list):
|
|||||||
try:
|
try:
|
||||||
raw = br.open_novisit(url).read()
|
raw = br.open_novisit(url).read()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
import socket
|
||||||
report(verbose)
|
report(verbose)
|
||||||
if callable(getattr(e, 'getcode', None)) and \
|
if callable(getattr(e, 'getcode', None)) and \
|
||||||
e.getcode() == 404:
|
e.getcode() == 404:
|
||||||
@ -353,11 +358,15 @@ def search(title=None, author=None, publisher=None, isbn=None,
|
|||||||
isbn=isbn, max_results=max_results,
|
isbn=isbn, max_results=max_results,
|
||||||
min_viewability=min_viewability)(br, verbose)
|
min_viewability=min_viewability)(br, verbose)
|
||||||
|
|
||||||
|
if entries is None or len(entries) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
ans = ResultList()
|
ans = ResultList()
|
||||||
ans.populate(entries, br, verbose)
|
ans.populate(entries, br, verbose)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
|
import textwrap
|
||||||
parser = OptionParser(textwrap.dedent(
|
parser = OptionParser(textwrap.dedent(
|
||||||
_('''\
|
_('''\
|
||||||
%prog [options]
|
%prog [options]
|
||||||
@ -392,7 +401,7 @@ def main(args=sys.argv):
|
|||||||
print _('No result found for this search!')
|
print _('No result found for this search!')
|
||||||
return 0
|
return 0
|
||||||
for result in results:
|
for result in results:
|
||||||
print unicode(result).encode(preferred_encoding)
|
print unicode(result).encode(preferred_encoding, 'replace')
|
||||||
print
|
print
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user