Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a language field to the "get ebooks" dialog. #664

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/calibre/gui2/store/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from calibre.gui2.store.search.download_thread import DetailsThreadPool, \
CoverThreadPool
from calibre.utils.icu import sort_key
from calibre.utils.localization import get_language
from calibre.utils.search_query_parser import SearchQueryParser


Expand All @@ -38,7 +39,7 @@ class Matches(QAbstractItemModel):

total_changed = pyqtSignal(int)

HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('Download'), _('Affiliate')]
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('Download'), _('Affiliate'), _('Language')]
HTML_COLS = (1, 4)
IMG_COLS = (0, 3, 5, 6)

Expand Down Expand Up @@ -207,6 +208,8 @@ def data(self, index, role):
return (result.price)
elif col == 4:
return ('<span>%s<br>%s</span>' % (result.store_name, result.formats))
elif col == 7:
return get_language(result.language)
return None
elif role == Qt.DecorationRole:
if col == 0 and result.cover_data:
Expand Down
2 changes: 2 additions & 0 deletions src/calibre/gui2/store/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def resize_columns(self):
self.results_view.setColumnWidth(5, 20)
# Affiliate
self.results_view.setColumnWidth(6, 20)
# Language
self.results_view.setColumnWidth(7, 10)

def toggle_search(self):
if self.searching:
Expand Down
1 change: 1 addition & 0 deletions src/calibre/gui2/store/search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
# value = url to download the file.
self.downloads = {}
self.affiliate = False
self.language = ''
self.plugin_author = ''
self.create_browser = None

Expand Down
15 changes: 15 additions & 0 deletions src/calibre/gui2/store/stores/amazon_au_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def search(self, query, max_results=10, timeout=60):
for result in search_amazon(query, max_results=max_results, timeout=timeout):
yield result

def get_language(self, idata):
self.language_xpath = '''
descendant::*[
starts-with(text(), "Language:") \
or text() = "Language" \
]
'''
for x in reversed(idata.xpath(self.language_xpath)):
if x.tail:
raw = x.tail.strip().partition(',')[0].strip()
ans = canonicalize_lang(raw)
if ans:
return ans

def get_details(self, search_result, timeout):
url = DETAILS_URL

Expand All @@ -140,6 +154,7 @@ def get_details(self, search_result, timeout):
search_result.drm = SearchResult.DRM_UNKNOWN
else:
search_result.drm = SearchResult.DRM_LOCKED
search_result.language = self.get_language(idata) or ''
return True


Expand Down
15 changes: 15 additions & 0 deletions src/calibre/gui2/store/stores/amazon_ca_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def search(self, query, max_results=10, timeout=60):
for result in search_amazon(query, max_results=max_results, timeout=timeout):
yield result

def get_language(self, idata):
self.language_xpath = '''
descendant::*[
starts-with(text(), "Language:") \
or text() = "Language" \
]
'''
for x in reversed(idata.xpath(self.language_xpath)):
if x.tail:
raw = x.tail.strip().partition(',')[0].strip()
ans = canonicalize_lang(raw)
if ans:
return ans

def get_details(self, search_result, timeout):
url = DETAILS_URL

Expand All @@ -140,6 +154,7 @@ def get_details(self, search_result, timeout):
search_result.drm = SearchResult.DRM_UNKNOWN
else:
search_result.drm = SearchResult.DRM_LOCKED
search_result.language = self.get_language(idata) or ''
return True


Expand Down
15 changes: 15 additions & 0 deletions src/calibre/gui2/store/stores/amazon_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ def search(self, query, max_results=10, timeout=60):
for result in search_amazon(query, max_results=max_results, timeout=timeout):
yield result

def get_language(self, idata):
self.language_xpath = '''
descendant::*[
starts-with(text(), "Language:") \
or text() = "Language" \
]
'''
for x in reversed(idata.xpath(self.language_xpath)):
if x.tail:
raw = x.tail.strip().partition(',')[0].strip()
ans = canonicalize_lang(raw)
if ans:
return ans

def get_details(self, search_result, timeout):
url = DETAILS_URL

Expand All @@ -177,6 +191,7 @@ def get_details(self, search_result, timeout):
search_result.drm = SearchResult.DRM_UNKNOWN
else:
search_result.drm = SearchResult.DRM_LOCKED
search_result.language = self.get_language(idata) or ''
return True


Expand Down
15 changes: 15 additions & 0 deletions src/calibre/gui2/store/stores/amazon_uk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def search(self, query, max_results=10, timeout=60):
for result in search_amazon(query, max_results=max_results, timeout=timeout):
yield result

def get_language(self, idata):
self.language_xpath = '''
descendant::*[
starts-with(text(), "Language:") \
or text() = "Language" \
]
'''
for x in reversed(idata.xpath(self.language_xpath)):
if x.tail:
raw = x.tail.strip().partition(',')[0].strip()
ans = canonicalize_lang(raw)
if ans:
return ans

def get_details(self, search_result, timeout):
url = DETAILS_URL

Expand All @@ -140,6 +154,7 @@ def get_details(self, search_result, timeout):
search_result.drm = SearchResult.DRM_UNKNOWN
else:
search_result.drm = SearchResult.DRM_LOCKED
search_result.language = self.get_language(idata) or ''
return True


Expand Down