From 7a2a5bbdd926fb42008e7ebc6fc99f755fdc2142 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 2 Jul 2014 18:19:30 +0530 Subject: [PATCH] When reading metadata from file names, allow setting the comments field as well, in addition to title/authros/publisher/series/etc. Fixes #1332582 [some add book regexp bugs and suggestion](https://bugs.launchpad.net/calibre/+bug/1332582) --- src/calibre/ebooks/metadata/meta.py | 5 +++++ src/calibre/gui2/filename_pattern.ui | 26 +++++++++++++++++++++++--- src/calibre/gui2/widgets.py | 12 +++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/metadata/meta.py b/src/calibre/ebooks/metadata/meta.py index f9ac3a75cf..7e1fb05c62 100644 --- a/src/calibre/ebooks/metadata/meta.py +++ b/src/calibre/ebooks/metadata/meta.py @@ -184,6 +184,11 @@ def metadata_from_filename(name, pat=None, fallback_pat=None): mi.pubdate = parse_only_date(pubdate) except: pass + try: + comments = match.group('comments') + mi.comments = comments + except (IndexError, ValueError): + pass if mi.is_null('title'): mi.title = name diff --git a/src/calibre/gui2/filename_pattern.ui b/src/calibre/gui2/filename_pattern.ui index 87c19af869..48cc109f84 100644 --- a/src/calibre/gui2/filename_pattern.ui +++ b/src/calibre/gui2/filename_pattern.ui @@ -101,8 +101,8 @@ 0 0 - 305 - 263 + 301 + 284 @@ -116,7 +116,7 @@ - Regular expression (?P<title>) + Regular expression (?P&lt;title&gt;) No match @@ -246,6 +246,26 @@ + + + + Comments: + + + + + + + Regular expression (?P<comments>) + + + No match + + + true + + + diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 3d6ff36f10..336b876388 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -71,7 +71,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{ self.re.lineEdit().textChanged.connect(lambda x: self.changed_signal.emit()) def initialize(self, defaults=False): - # Get all itmes in the combobox. If we are resting + # Get all items in the combobox. If we are resting # to defaults we don't want to lose what the user # has added. val_hist = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())] @@ -95,6 +95,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{ self.re.setCurrentIndex(0) def do_test(self): + from calibre.ebooks.metadata import authors_to_string from calibre.ebooks.metadata.meta import metadata_from_filename fname = unicode(self.filename.text()) ext = os.path.splitext(fname)[1][1:].lower() @@ -116,7 +117,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{ else: self.title.setText(_('No match')) if mi.authors: - self.authors.setText(', '.join(mi.authors)) + self.authors.setText(authors_to_string(mi.authors)) else: self.authors.setText(_('No match')) @@ -132,11 +133,16 @@ class FilenamePattern(QWidget, Ui_Form): # {{{ if mi.publisher: self.publisher.setText(mi.publisher) + else: + self.publisher.setText(_('No match')) if mi.pubdate: self.pubdate.setText(mi.pubdate.strftime('%Y-%m-%d')) + else: + self.pubdate.setText(_('No match')) self.isbn.setText(_('No match') if mi.isbn is None else str(mi.isbn)) + self.comments.setText(mi.comments if mi.comments else _('No match')) def pattern(self): pat = unicode(self.re.lineEdit().text()) @@ -148,7 +154,7 @@ class FilenamePattern(QWidget, Ui_Form): # {{{ history = [] history_pats = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())] - for p in history_pats[:14]: + for p in history_pats[:24]: # Ensure we don't have duplicate items. if p and p not in history: history.append(p)