A spot of refactoring

This commit is contained in:
Kovid Goyal 2016-12-02 09:50:17 +05:30
parent 2b562831d7
commit f1484411af

View File

@ -20,12 +20,7 @@ from calibre.utils.opensearch.description import Description
from calibre.utils.opensearch.query import Query from calibre.utils.opensearch.query import Query
class ManyBooksStore(BasicStoreConfig, OpenSearchOPDSStore): def search_manybooks(query, max_results=10, timeout=60, open_search_url='http://www.manybooks.net/opds/'):
open_search_url = 'http://www.manybooks.net/opds/'
web_url = 'http://manybooks.net'
def search(self, query, max_results=10, timeout=60):
''' '''
Manybooks uses a very strange opds feed. The opds Manybooks uses a very strange opds feed. The opds
main feed is structured like a stanza feed. The main feed is structured like a stanza feed. The
@ -34,10 +29,8 @@ class ManyBooksStore(BasicStoreConfig, OpenSearchOPDSStore):
link has the wrong type specified (text/html instead link has the wrong type specified (text/html instead
of application/atom+xml). of application/atom+xml).
''' '''
if not hasattr(self, 'open_search_url'):
return
description = Description(self.open_search_url) description = Description(open_search_url)
url_template = description.get_best_template() url_template = description.get_best_template()
if not url_template: if not url_template:
return return
@ -108,3 +101,19 @@ class ManyBooksStore(BasicStoreConfig, OpenSearchOPDSStore):
s.formats = 'EPUB, PDB (eReader, PalmDoc, zTXT, Plucker, iSilo), FB2, ZIP, AZW, MOBI, PRC, LIT, PKG, PDF, TXT, RB, RTF, LRF, TCR, JAR' s.formats = 'EPUB, PDB (eReader, PalmDoc, zTXT, Plucker, iSilo), FB2, ZIP, AZW, MOBI, PRC, LIT, PKG, PDF, TXT, RB, RTF, LRF, TCR, JAR'
yield s yield s
class ManyBooksStore(BasicStoreConfig, OpenSearchOPDSStore):
open_search_url = 'http://www.manybooks.net/opds/'
web_url = 'http://manybooks.net'
def search(self, query, max_results=10, timeout=60):
for r in search_manybooks(query, max_results=max_results, timeout=timeout, open_search_url=self.open_search_url):
yield r
if __name__ == '__main__':
import sys
for result in search_manybooks(' '.join(sys.argv[1:])):
print (result)