Fixes #1968897 [Edit Metadata: Google identifiers paste as url:](https://bugs.launchpad.net/calibre/+bug/1968897)
This commit is contained in:
Kovid Goyal 2022-04-15 08:24:37 +05:30
parent 2b40d1dbfb
commit 205db05475
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 31 additions and 27 deletions

View File

@ -2042,8 +2042,8 @@ class KOBOTOUCH(KOBO):
int(row['FavouritesIndex']), row['Accessibility'], row['IsDownloaded'], int(row['FavouritesIndex']), row['Accessibility'], row['IsDownloaded'],
row['___UserID'], bookshelves, row['___UserID'], bookshelves,
book_stats={ book_stats={
'StorePages': row['StorePages'], 'StorePages': row['StorePages'],
'StoreWordCount': row['StoreWordCount'], 'StoreWordCount': row['StoreWordCount'],
'StoreTimeToReadLowerEstimate': row['StoreTimeToReadLowerEstimate'], 'StoreTimeToReadLowerEstimate': row['StoreTimeToReadLowerEstimate'],
'StoreTimeToReadUpperEstimate': row['StoreTimeToReadUpperEstimate'] 'StoreTimeToReadUpperEstimate': row['StoreTimeToReadUpperEstimate']
} }
@ -3223,14 +3223,15 @@ class KOBOTOUCH(KOBO):
debug_print("KoboTouch:generate_update_from_template template error - template='%s'" % template) debug_print("KoboTouch:generate_update_from_template template error - template='%s'" % template)
debug_print("KoboTouch:generate_update_from_template - new_value=", new_value) debug_print("KoboTouch:generate_update_from_template - new_value=", new_value)
debug_print(f"KoboTouch:generate_update_from_template - {book.title} - column_name='{column_name}', current_value='{current_value}', new_value='{new_value}'") debug_print(
if (new_value is not None and \ f"KoboTouch:generate_update_from_template - {book.title} - column_name='{column_name}',"
(current_value is None or new_value != current_value) ) or \ f" current_value='{current_value}', new_value='{new_value}'")
if (new_value is not None and
(current_value is None or new_value != current_value)) or \
(new_value is None and current_value is not None): (new_value is None and current_value is not None):
update_values.append(new_value) update_values.append(new_value)
set_clause.append(column_name) set_clause.append(column_name)
plugboard = None plugboard = None
if self.plugboard_func and not series_only: if self.plugboard_func and not series_only:
if book.contentID.endswith('.kepub.epub') or not os.path.splitext(book.contentID)[1]: if book.contentID.endswith('.kepub.epub') or not os.path.splitext(book.contentID)[1]:
@ -3368,34 +3369,34 @@ class KOBOTOUCH(KOBO):
if self.update_bookstats: if self.update_bookstats:
if self.bookstats_pagecount_template is not None: if self.bookstats_pagecount_template is not None:
current_bookstats_pagecount = book.kobo_bookstats.get('StorePages', None) current_bookstats_pagecount = book.kobo_bookstats.get('StorePages', None)
generate_update_from_template(book, update_values, set_clause, generate_update_from_template(book, update_values, set_clause,
column_name='StorePages', column_name='StorePages',
template=self.bookstats_pagecount_template, template=self.bookstats_pagecount_template,
new_value=book.bookstats_pagecount, new_value=book.bookstats_pagecount,
current_value=current_bookstats_pagecount current_value=current_bookstats_pagecount
) )
if self.bookstats_wordcount_template is not None: if self.bookstats_wordcount_template is not None:
current_bookstats_wordcount = book.kobo_bookstats.get('StoreWordCount', None) current_bookstats_wordcount = book.kobo_bookstats.get('StoreWordCount', None)
generate_update_from_template(book, update_values, set_clause, generate_update_from_template(book, update_values, set_clause,
column_name='StoreWordCount', column_name='StoreWordCount',
template=self.bookstats_wordcount_template, template=self.bookstats_wordcount_template,
new_value=book.bookstats_wordcount, new_value=book.bookstats_wordcount,
current_value=current_bookstats_wordcount current_value=current_bookstats_wordcount
) )
if self.bookstats_timetoread_upper_template is not None: if self.bookstats_timetoread_upper_template is not None:
current_bookstats_timetoread_upper = book.kobo_bookstats.get('StoreTimeToReadUpperEstimate', None) current_bookstats_timetoread_upper = book.kobo_bookstats.get('StoreTimeToReadUpperEstimate', None)
generate_update_from_template(book, update_values, set_clause, generate_update_from_template(book, update_values, set_clause,
column_name='StoreTimeToReadUpperEstimate', column_name='StoreTimeToReadUpperEstimate',
template=self.bookstats_timetoread_upper_template, template=self.bookstats_timetoread_upper_template,
new_value=book.bookstats_timetoread_upper, new_value=book.bookstats_timetoread_upper,
current_value=current_bookstats_timetoread_upper current_value=current_bookstats_timetoread_upper
) )
if self.bookstats_timetoread_lower_template is not None: if self.bookstats_timetoread_lower_template is not None:
current_bookstats_timetoread_lower = book.kobo_bookstats.get('StoreTimeToReadLowerEstimate', None) current_bookstats_timetoread_lower = book.kobo_bookstats.get('StoreTimeToReadLowerEstimate', None)
generate_update_from_template(book, update_values, set_clause, generate_update_from_template(book, update_values, set_clause,
column_name='StoreTimeToReadLowerEstimate', column_name='StoreTimeToReadLowerEstimate',
template=self.bookstats_timetoread_lower_template, template=self.bookstats_timetoread_lower_template,
new_value=book.bookstats_timetoread_lower, new_value=book.bookstats_timetoread_lower,
current_value=current_bookstats_timetoread_lower current_value=current_bookstats_timetoread_lower
) )
@ -3427,7 +3428,6 @@ class KOBOTOUCH(KOBO):
if show_debug: if show_debug:
debug_print("KoboTouch:set_core_metadata - end") debug_print("KoboTouch:set_core_metadata - end")
@classmethod @classmethod
def config_widget(cls): def config_widget(cls):
# TODO: Cleanup the following # TODO: Cleanup the following

View File

@ -693,15 +693,19 @@ class MetadataGroupBox(DeviceOptionsGroupBox):
@property @property
def update_bookstats(self): def update_bookstats(self):
return self.update_bookstats_checkbox.isChecked() return self.update_bookstats_checkbox.isChecked()
@property @property
def bookstats_pagecount_template(self): def bookstats_pagecount_template(self):
return self.bookstats_pagecount_template_edit.template return self.bookstats_pagecount_template_edit.template
@property @property
def bookstats_wordcount_template(self): def bookstats_wordcount_template(self):
return self.bookstats_wordcount_template_edit.template return self.bookstats_wordcount_template_edit.template
@property @property
def bookstats_timetoread_lower_template(self): def bookstats_timetoread_lower_template(self):
return self.bookstats_timetoread_lower_template_edit.template return self.bookstats_timetoread_lower_template_edit.template
@property @property
def bookstats_timetoread_upper_template(self): def bookstats_timetoread_upper_template(self):
return self.bookstats_timetoread_upper_template_edit.template return self.bookstats_timetoread_upper_template_edit.template
@ -709,6 +713,7 @@ class MetadataGroupBox(DeviceOptionsGroupBox):
from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor
class TemplateConfig(QWidget): # {{{ class TemplateConfig(QWidget): # {{{
def __init__(self, val, label=None, tooltip=None): def __init__(self, val, label=None, tooltip=None):

View File

@ -201,7 +201,7 @@ class GoogleBooks(Source):
# }}} # }}}
def id_from_url(self, url): # {{{ def id_from_url(self, url): # {{{
url_pattern = '(?:http|https)://books\.google\.com/books\?id=(?P<id_>.+)' url_pattern = r'(?:http|https)://books\.google\.com/books\?id=(?P<id_>.+)'
url_pattern = re.compile(url_pattern) url_pattern = re.compile(url_pattern)
id_ = url_pattern.search(url).group('id_') id_ = url_pattern.search(url).group('id_')
if id_: if id_:

View File

@ -4,7 +4,6 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import defaultdict
from functools import partial from functools import partial
from qt.core import (QTimer, QApplication, Qt, QEvent, QDialog, QMenu, QIcon, from qt.core import (QTimer, QApplication, Qt, QEvent, QDialog, QMenu, QIcon,