diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 361b5f9..7c35407 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -27,7 +27,7 @@ class FanFictionDownLoaderBase(InterfaceActionBase): description = 'UI plugin to download FanFiction stories from various sites.' supported_platforms = ['windows', 'osx', 'linux'] author = 'Jim Miller' - version = (1, 1, 2) + version = (1, 1, 3) minimum_calibre_version = (0, 8, 30) #: This field defines the GUI plugin class that contains all the code diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 7d09338..85e63da 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -27,6 +27,7 @@ prefs = JSONConfig('plugins/fanfictiondownloader_plugin') # Set defaults prefs.defaults['personal.ini'] = get_resources('example.ini') prefs.defaults['updatemeta'] = True +prefs.defaults['keeptags'] = False #prefs.defaults['onlyoverwriteifnewer'] = False prefs.defaults['urlsfromclip'] = True prefs.defaults['updatedefault'] = True @@ -72,10 +73,15 @@ class ConfigWidget(QWidget): self.l.addLayout(horz) self.updatemeta = QCheckBox('Default Update Calibre &Metadata?',self) - self.updatemeta.setToolTip('Update metadata for story in Calibre from web site?') + self.updatemeta.setToolTip('Update title, author, URL, tags, etc for story in Calibre from web site.') self.updatemeta.setChecked(prefs['updatemeta']) self.l.addWidget(self.updatemeta) + self.keeptags = QCheckBox('Keep Existing Tags when Updating Metadata?',self) + self.keeptags.setToolTip('Existing tags will be kept and any new tags added.\nCompleted and In-Progress tags will be still be updated, if known.\nLast Updated tags will be updated if lastupdate in include_subject_tags.') + self.keeptags.setChecked(prefs['keeptags']) + self.l.addWidget(self.keeptags) + # self.onlyoverwriteifnewer = QCheckBox('Default Only Overwrite Story if Newer',self) # self.onlyoverwriteifnewer.setToolTip("Don't overwrite existing book unless the story on the web site is newer or from the same day.") # self.onlyoverwriteifnewer.setChecked(prefs['onlyoverwriteifnewer']) @@ -130,6 +136,7 @@ class ConfigWidget(QWidget): prefs['fileform'] = unicode(self.fileform.currentText()) prefs['collision'] = unicode(self.collision.currentText()) prefs['updatemeta'] = self.updatemeta.isChecked() + prefs['keeptags'] = self.keeptags.isChecked() prefs['urlsfromclip'] = self.urlsfromclip.isChecked() prefs['updatedefault'] = self.updatedefault.isChecked() # prefs['onlyoverwriteifnewer'] = self.onlyoverwriteifnewer.isChecked() @@ -144,7 +151,7 @@ class ConfigWidget(QWidget): del prefs['personal.ini'] def show_defaults(self): - text = get_resources('defaults.ini') + text = get_resources('plugin-defaults.ini') ShowDefaultsIniDialog(self.windowIcon(),text,self).exec_() def reset_dialogs(self): diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 883dce9..ec6fd40 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -286,7 +286,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): ## was self.ffdlconfig, but we need to be able to change it ## when doing epub update. ffdlconfig = SafeConfigParser() - ffdlconfig.readfp(StringIO(get_resources("defaults.ini"))) + ffdlconfig.readfp(StringIO(get_resources("plugin-defaults.ini"))) ffdlconfig.readfp(StringIO(prefs['personal.ini'])) adapter = adapters.getAdapter(ffdlconfig,url) @@ -552,6 +552,17 @@ class FanFictionDownLoaderPlugin(InterfaceAction): if options['collision'] == CALIBREONLY or \ (options['updatemeta'] and book['good']) : + if prefs['keeptags']: + old_tags = db.get_tags(book['calibre_id']) + # remove old Completed/In-Progress only if there's a new one. + if 'Completed' in mi.tags or 'In-Progress' in mi.tags: + old_tags = filter( lambda x : x not in ('Completed', 'In-Progress'), old_tags) + # remove old Last Update tags if there are new ones. + if len(filter( lambda x : not x.startswith("Last Update"), mi.tags)) > 0: + old_tags = filter( lambda x : not x.startswith("Last Update"), old_tags) + # mi.tags needs to be list, but set kills dups. + mi.tags = list(set(list(old_tags)+mi.tags)) + db.set_metadata(book['calibre_id'],mi) add_list = filter(lambda x : x['good'] and x['added'], book_list) diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index 287809d..182089d 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -103,14 +103,10 @@ def do_download_for_worker(book,options): when run as a worker job ''' try: - # print("is_adult:%s"%book['is_adult']) - # print("personal.ini len:%s"%len(options['personal.ini'])) - # print("defaults.ini len:%s"%len(get_resources("defaults.ini"))) - #time.sleep(2.0) book['comment'] = 'Download started...' ffdlconfig = SafeConfigParser() - ffdlconfig.readfp(StringIO(get_resources("defaults.ini"))) + ffdlconfig.readfp(StringIO(get_resources("plugin-defaults.ini"))) ffdlconfig.readfp(StringIO(options['personal.ini'])) adapter = adapters.getAdapter(ffdlconfig,book['url']) diff --git a/fanficdownloader/writers/base_writer.py b/fanficdownloader/writers/base_writer.py index 6fd5557..04142e3 100644 --- a/fanficdownloader/writers/base_writer.py +++ b/fanficdownloader/writers/base_writer.py @@ -249,11 +249,18 @@ class BaseStoryWriter(Configurable): def getTags(self): # set to avoid duplicates subject tags. subjectset = set() + + if self.story.getMetadataRaw('dateUpdated'): + # Last Update tags for Bill. + self.story.addToList('lastupdate',self.story.getMetadataRaw('dateUpdated').strftime("Last Update Year/Month: %Y/%m")) + self.story.addToList('lastupdate',self.story.getMetadataRaw('dateUpdated').strftime("Last Update: %Y/%m/%d")) + for entry in self.validEntries: if entry in self.getConfigList("include_subject_tags") and \ entry not in self.story.getLists() and \ self.story.getMetadata(entry): subjectset.add(self.getMetadata(entry)) + # listables all go into dc:subject tags, but only if they are configured. for (name,lst) in self.story.getLists().iteritems(): if name in self.getConfigList("include_subject_tags"): diff --git a/fanficdownloader/writers/writer_epub.py b/fanficdownloader/writers/writer_epub.py index bc16393..aa091bf 100644 --- a/fanficdownloader/writers/writer_epub.py +++ b/fanficdownloader/writers/writer_epub.py @@ -249,9 +249,6 @@ h6 { text-align: center; } metadata.appendChild(newTag(contentdom,"meta", attrs={"name":"calibre:timestamp", "content":self.story.getMetadataRaw('dateUpdated').strftime("%Y-%m-%dT%H:%M:%S")})) - # Last Update tags for Bill. - self.story.addToList('lastupdate',self.story.getMetadataRaw('dateUpdated').strftime("Last Update Year/Month: %Y/%m")) - self.story.addToList('lastupdate',self.story.getMetadataRaw('dateUpdated').strftime("Last Update: %Y/%m/%d")) if self.getMetadata('description'): metadata.appendChild(newTag(contentdom,"dc:description",text= diff --git a/makeplugin.py b/makeplugin.py index 45bbd29..9cdb3dc 100644 --- a/makeplugin.py +++ b/makeplugin.py @@ -27,7 +27,7 @@ if __name__=="__main__": exclude=['*.pyc','*~','*.xcf'] # from top dir. 'w' for overwrite createZipFile(filename,"w", - ['defaults.ini','example.ini','epubmerge.py','fanficdownloader'], + ['plugin-defaults.ini','example.ini','epubmerge.py','fanficdownloader'], exclude=exclude) #from calibre-plugin dir. 'a' for append os.chdir('calibre-plugin') diff --git a/plugin-defaults.ini b/plugin-defaults.ini new file mode 100644 index 0000000..8b22d85 --- /dev/null +++ b/plugin-defaults.ini @@ -0,0 +1,242 @@ +# Copyright 2012 Fanficdownloader team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +[defaults] + +## [defaults] section applies to all formats and sites but may be +## overridden at several levels + +## All available titlepage_entries and the label used for them: +## _label: