Skip to content

Commit

Permalink
Add media format and fiction/non-fiction options for Advanced Search
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Sep 28, 2023
1 parent 4098ce1 commit 093b71d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
55 changes: 55 additions & 0 deletions calibre-plugin/dialog/advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, *args):
self.identifier_txt.setClearButtonEnabled(True)
form_fields_layout.addRow(_("ISBN"), self.identifier_txt)

rb_layout_spacing = 10
self.availability_btn_group = QButtonGroup(self)
self.availability_all_rb = QRadioButton(_("All"), self)
self.availability_only_available_rb = QRadioButton(_("Available now"), self)
Expand All @@ -103,11 +104,47 @@ def __init__(self, *args):
self.availability_only_prelease_rb,
)
self.availability_rb_layout = QHBoxLayout()
self.availability_rb_layout.setSpacing(rb_layout_spacing)
for rb in availability_rb:
self.availability_btn_group.addButton(rb)
self.availability_rb_layout.addWidget(rb)
form_fields_layout.addRow(_("Availability"), self.availability_rb_layout)

if PREFS[PreferenceKeys.INCL_NONDOWNLOADABLE_TITLES]:
self.media_type_btn_group = QButtonGroup(self)
self.media_all_rb = QRadioButton(_("Any"), self)
self.media_ebook_rb = QRadioButton(_("Book"), self)
self.media_audiobook_rb = QRadioButton(_("Audiobook"), self)
self.media_magazine_rb = QRadioButton(_("Magazine"), self)
media_type_rb = (
self.media_all_rb,
self.media_ebook_rb,
self.media_audiobook_rb,
self.media_magazine_rb,
)
self.media_rb_layout = QHBoxLayout()
self.media_rb_layout.setSpacing(rb_layout_spacing)
for rb in media_type_rb:
self.media_type_btn_group.addButton(rb)
self.media_rb_layout.addWidget(rb)
form_fields_layout.addRow(_("Media"), self.media_rb_layout)

self.subject_btn_group = QButtonGroup(self)
self.subject_all_rb = QRadioButton(_("Any"), self)
self.subject_fiction_rb = QRadioButton(_("Fiction"), self)
self.subject_nonfiction_rb = QRadioButton(_("Nonfiction"), self)
subject_rb = (
self.subject_all_rb,
self.subject_fiction_rb,
self.subject_nonfiction_rb,
)
self.subject_rb_layout = QHBoxLayout()
self.subject_rb_layout.setSpacing(rb_layout_spacing)
for rb in subject_rb:
self.subject_btn_group.addButton(rb)
self.subject_rb_layout.addWidget(rb)
form_fields_layout.addRow(_("Subject"), self.subject_rb_layout)

# Search button
self.adv_search_btn = DefaultQPushButton(
_c("Search"), self.resources[PluginImages.Search], self
Expand Down Expand Up @@ -312,6 +349,22 @@ def adv_search_btn_clicked(self):
LibbyFormats.AudioBookMP3,
LibbyFormats.AudioBookOverDrive,
]

media_type = ""
if PREFS[PreferenceKeys.INCL_NONDOWNLOADABLE_TITLES]:
if self.media_ebook_rb.isChecked():
media_type = "ebook"
elif self.media_audiobook_rb.isChecked():
media_type = "audiobook"
elif self.media_magazine_rb.isChecked():
media_type = "magazine"

subject_id = ""
if self.subject_nonfiction_rb.isChecked():
subject_id = "111"
elif self.subject_fiction_rb.isChecked():
subject_id = "26"

query = LibraryMediaSearchParams(
query=self.adv_query_txt.text(),
title=self.title_txt.text(),
Expand All @@ -320,6 +373,8 @@ def adv_search_btn_clicked(self):
show_only_available=self.availability_only_available_rb.isChecked(),
show_only_prelease=self.availability_only_prelease_rb.isChecked(),
formats=formats,
media_type=media_type,
subject_id=subject_id,
per_page=PREFS[PreferenceKeys.SEARCH_RESULTS_MAX],
)
if query.is_empty():
Expand Down
8 changes: 8 additions & 0 deletions calibre-plugin/overdrive/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class LibraryMediaSearchParams:
sort_by: str = SearchSortBy.RELEVANCE
show_only_available: bool = False
show_only_prelease: bool = False
media_type: str = ""
subject_id: str = ""
title_ids: List[str] = field(default_factory=list)

def is_empty(self) -> bool:
Expand All @@ -63,6 +65,8 @@ def is_empty(self) -> bool:
or self.show_only_available
or self.show_only_prelease
or self.title_ids
or self.media_type
or self.subject_id
)

def convert_bool(self, value: bool):
Expand All @@ -87,6 +91,10 @@ def to_dict(self) -> Dict:
result[a] = str(v).strip()
if self.title_ids:
result["titleIds"] = ",".join(self.title_ids)
if self.media_type:
result["mediaTypes"] = self.media_type
if self.subject_id:
result["subject"] = self.subject_id
return result


Expand Down

0 comments on commit 093b71d

Please sign in to comment.