diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py
index 0708124..3fc7c64 100644
--- a/calibre-plugin/config.py
+++ b/calibre-plugin/config.py
@@ -272,6 +272,7 @@ class ConfigWidget(QWidget):
prefs['addtolists'] = self.readinglist_tab.addtolists.isChecked()
prefs['addtoreadlists'] = self.readinglist_tab.addtoreadlists.isChecked()
prefs['addtolistsonread'] = self.readinglist_tab.addtolistsonread.isChecked()
+ prefs['autounnew'] = self.readinglist_tab.autounnew.isChecked()
# personal.ini
ini = self.personalini_tab.personalini
@@ -781,6 +782,11 @@ class ReadingListTab(QWidget):
self.addtolistsonread.setChecked(prefs['addtolistsonread'])
self.l.addWidget(self.addtolistsonread)
+ self.autounnew = QCheckBox(_('Automatically run Remove "New" Chapter Marks when marking books "Read".'),self)
+ self.autounnew.setToolTip(_('Menu option to remove from "To Read" lists will also remove "(new)" chapter marks created by personal.ini mark_new_chapters setting.'))
+ self.autounnew.setChecked(prefs['autounnew'])
+ self.l.addWidget(self.autounnew)
+
self.l.insertStretch(-1)
class CalibreCoverTab(QWidget):
diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py
index feae7c2..d7241e1 100644
--- a/calibre-plugin/fff_plugin.py
+++ b/calibre-plugin/fff_plugin.py
@@ -337,9 +337,9 @@ class FanFicFarePlugin(InterfaceAction):
triggered=partial(self.update_lists,add=False))
self.menu.addSeparator()
- self.get_list_action = self.create_menu_item_ex(self.menu, _('UnNew Selected books'),
- unique_name='Get URLs from Selected Books',
- image='rotate-right.png',
+ self.get_list_action = self.create_menu_item_ex(self.menu, _('Remove "New" Chapter Marks from Selected books'),
+ unique_name='Remove "(new)" chapter marks created by personal.ini mark_new_chapters setting.',
+ image='edit-undo.png',
triggered=self.unnew_books)
self.menu.addSeparator()
@@ -422,7 +422,8 @@ class FanFicFarePlugin(InterfaceAction):
return
self.update_reading_lists(self.gui.library_view.get_selected_ids(),add)
- self.unnew_books()
+ if not add and prefs['autounnew']:
+ self.unnew_books()
def get_urls_from_imap_menu(self):
diff --git a/calibre-plugin/prefs.py b/calibre-plugin/prefs.py
index 69496c8..0dd8afd 100644
--- a/calibre-plugin/prefs.py
+++ b/calibre-plugin/prefs.py
@@ -85,6 +85,7 @@ default_prefs['read_lists'] = ''
default_prefs['addtolists'] = False
default_prefs['addtoreadlists'] = False
default_prefs['addtolistsonread'] = False
+default_prefs['autounnew'] = False
default_prefs['updatecalcover'] = None
default_prefs['gencalcover'] = SAVE_YES
diff --git a/fanficfare/cli.py b/fanficfare/cli.py
index 32ae102..f9ab6d3 100644
--- a/fanficfare/cli.py
+++ b/fanficfare/cli.py
@@ -41,12 +41,14 @@ try:
# running under calibre
from calibre_plugins.fanfictiondownloader_plugin.fanficfare import adapters, writers, exceptions
from calibre_plugins.fanfictiondownloader_plugin.fanficfare.configurable import Configuration
- from calibre_plugins.fanfictiondownloader_plugin.fanficfare.epubutils import get_dcsource_chaptercount, get_update_data
+ from calibre_plugins.fanfictiondownloader_plugin.fanficfare.epubutils import (
+ get_dcsource_chaptercount, get_update_data, reset_orig_chapters_epub)
from calibre_plugins.fanfictiondownloader_plugin.fanficfare.geturls import get_urls_from_page
except ImportError:
from fanficfare import adapters, writers, exceptions
from fanficfare.configurable import Configuration
- from fanficfare.epubutils import get_dcsource_chaptercount, get_update_data
+ from fanficfare.epubutils import (
+ get_dcsource_chaptercount, get_update_data, reset_orig_chapters_epub)
from fanficfare.geturls import get_urls_from_page
@@ -87,6 +89,9 @@ def main(argv=None, parser=None, passed_defaultsini=None, passed_personalini=Non
parser.add_option('-u', '--update-epub',
action='store_true', dest='update',
help='Update an existing epub with new chapters, give epub filename instead of storyurl.', )
+ parser.add_option('--unnew',
+ action='store_true', dest='unnew',
+ help='Remove (new) chapter marks left by mark_new_chapters setting.', )
parser.add_option('--update-cover',
action='store_true', dest='updatecover',
help='Update cover in an existing epub, otherwise existing cover (if any) is used on update. Only valid with --update-epub.', )
@@ -129,6 +134,9 @@ def main(argv=None, parser=None, passed_defaultsini=None, passed_personalini=Non
if options.update and options.format != 'epub':
parser.error('-u/--update-epub only works with epub')
+ if options.unnew and options.format != 'epub':
+ parser.error('--unnew-epub only works with epub')
+
# for passing in a file list
if options.infile:
urls=[]
@@ -168,6 +176,12 @@ def do_download(arg,
# Attempt to update an existing epub.
chaptercount = None
output_filename = None
+
+ if options.unnew:
+ # remove mark_new_chapters marks
+ reset_orig_chapters_epub(arg,arg)
+ return
+
if options.update:
try:
url, chaptercount = get_dcsource_chaptercount(arg)
diff --git a/fanficfare/epubutils.py b/fanficfare/epubutils.py
index 8f92ca2..deaa908 100644
--- a/fanficfare/epubutils.py
+++ b/fanficfare/epubutils.py
@@ -1,11 +1,10 @@
-#!/usr/bin/env python
-# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
# -*- coding: utf-8 -*-
-from __future__ import (unicode_literals, division, absolute_import,
- print_function)
+
+# from __future__ import (unicode_literals, division, absolute_import,
+# print_function)
__license__ = 'GPL v3'
-__copyright__ = '2014, Jim Miller'
+__copyright__ = '2015, Jim Miller'
__docformat__ = 'restructuredtext en'
import logging
@@ -15,6 +14,7 @@ import re, os, traceback
from collections import defaultdict
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
from xml.dom.minidom import parseString
+from StringIO import StringIO
import bs4 as bs
@@ -177,7 +177,7 @@ def get_update_data(inputio,
#for k in images.keys():
#print("\tlongdesc:%s\n\tData len:%s\n"%(k,len(images[k])))
- print("datamaps:%s"%datamaps)
+ # print("datamaps:%s"%datamaps)
return (source,filecount,soups,images,oldcover,calibrebookmark,logfile,urlsoups,datamaps)
def get_path_part(n):
@@ -223,20 +223,23 @@ def get_story_url_from_html(inputio,_is_good_url=None):
return ahref
return None
-def reset_orig_chapters_epub(inputio,outputio):
+def reset_orig_chapters_epub(inputio,outfile):
inputepub = ZipFile(inputio, 'r') # works equally well with a path or a blob
+ ## build zip in memory in case updating in place(CLI).
+ zipio = StringIO()
+
## Write mimetype file, must be first and uncompressed.
## Older versions of python(2.4/5) don't allow you to specify
## compression by individual file.
## Overwrite if existing output file.
- outputepub = ZipFile(outputio, 'w', compression=ZIP_STORED)
+ outputepub = ZipFile(zipio, 'w', compression=ZIP_STORED)
outputepub.debug = 3
outputepub.writestr("mimetype", "application/epub+zip")
outputepub.close()
## Re-open file for content.
- outputepub = ZipFile(outputio, "a", compression=ZIP_DEFLATED)
+ outputepub = ZipFile(zipio, "a", compression=ZIP_DEFLATED)
outputepub.debug = 3
changed = False
@@ -246,8 +249,8 @@ def reset_orig_chapters_epub(inputio,outputio):
for zf in inputepub.namelist():
if zf not in ['mimetype','toc.ncx'] :
data = inputepub.read(zf)
- if isinstance(data,unicode):
- print("\n\n\ndata is unicode\n\n\n")
+ # if isinstance(data,unicode):
+ # logger.debug("\n\n\ndata is unicode\n\n\n")
if re.match(r'.*/file\d+\.xhtml',zf):
data = data.decode('utf-8')
soup = bs.BeautifulSoup(data,"html5lib")
@@ -265,7 +268,7 @@ def reset_orig_chapters_epub(inputio,outputio):
if chaptertitle and chapterorigtitle and chapterorigtitle != chaptertitle:
origdata = data
origtocncx = tocncx
- print("\n%s\n%s\n"%(chapterorigtitle,chaptertitle))
+ # print("\n%s\n%s\n"%(chapterorigtitle,chaptertitle))
# changed = True
# data = data.replace(u'',
# u''+chapterorigtitle+u'')
@@ -277,6 +280,22 @@ def reset_orig_chapters_epub(inputio,outputio):
else:
outputepub.writestr(zf,data)
- outputepub.writestr('toc.ncx',tocncx.encode('utf-8'))
+ # only write if changed.
+ if changed:
+ outputepub.writestr('toc.ncx',tocncx.encode('utf-8'))
+
+ # declares all the files created by Windows. otherwise, when
+ # it runs in appengine, windows unzips the files as 000 perms.
+ for zf in outputepub.filelist:
+ zf.create_system = 0
+ outputepub.close()
+ if isinstance(outfile,basestring):
+ with open(outfile,"wb") as outputio:
+ outputio.write(zipio.getvalue())
+ else:
+ outfile.write(zipio.getvalue())
+
+ inputepub.close()
+ zipio.close()
return changed