mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
84205d79cd
commit
7a2a5bbdd9
@ -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
|
||||
|
@ -101,8 +101,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>305</width>
|
||||
<height>263</height>
|
||||
<width>301</width>
|
||||
<height>284</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
@ -116,7 +116,7 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="title">
|
||||
<property name="toolTip">
|
||||
<string>Regular expression (?P<title>)</string>
|
||||
<string>Regular expression (?P&lt;title&gt;)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No match</string>
|
||||
@ -246,6 +246,26 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Comments:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLineEdit" name="comments">
|
||||
<property name="toolTip">
|
||||
<string>Regular expression (?P<comments>)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No match</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user