From 9bf00e26bb7e4df3c82bcc98ecb253183a2028de Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Jul 2017 23:42:20 +0530 Subject: [PATCH] A spot of refactoring --- .../gui2/store/stores/archive_org_plugin.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/stores/archive_org_plugin.py b/src/calibre/gui2/store/stores/archive_org_plugin.py index d43a201d68..b231d364f3 100644 --- a/src/calibre/gui2/store/stores/archive_org_plugin.py +++ b/src/calibre/gui2/store/stores/archive_org_plugin.py @@ -8,20 +8,33 @@ __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' from calibre.gui2.store.basic_config import BasicStoreConfig -from calibre.gui2.store.opensearch_store import OpenSearchOPDSStore +from calibre.gui2.store.opensearch_store import OpenSearchOPDSStore, open_search from calibre.gui2.store.search_result import SearchResult +SEARCH_URL = 'http://bookserver.archive.org/catalog/opensearch.xml' + + +def search(query, max_results=10, timeout=60): + for result in open_search(SEARCH_URL, query, max_results=max_results, timeout=timeout): + yield result + class ArchiveOrgStore(BasicStoreConfig, OpenSearchOPDSStore): - open_search_url = 'http://bookserver.archive.org/catalog/opensearch.xml' + open_search_url = SEARCH_URL web_url = 'http://www.archive.org/details/texts' # http://bookserver.archive.org/catalog/ def search(self, query, max_results=10, timeout=60): - for s in OpenSearchOPDSStore.search(self, query, max_results, timeout): + for s in search(query, max_results, timeout): s.detail_item = 'http://www.archive.org/details/' + s.detail_item.split(':')[-1] s.price = '$0.00' s.drm = SearchResult.DRM_UNLOCKED yield s + + +if __name__ == '__main__': + import sys + for s in search(' '.join(sys.argv[1:])): + print(s)