mirror of
https://github.com/wassname/FanFicFare.git
synced 2026-09-09 11:14:08 +08:00
Make UnNew on 'mark read' optional, add '--unnew' option to CLI.
This commit is contained in:
@@ -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 <i>mark_new_chapters</i> setting.'))
|
||||
self.autounnew.setChecked(prefs['autounnew'])
|
||||
self.l.addWidget(self.autounnew)
|
||||
|
||||
self.l.insertStretch(-1)
|
||||
|
||||
class CalibreCoverTab(QWidget):
|
||||
|
||||
@@ -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 <i>mark_new_chapters</i> 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):
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+16
-2
@@ -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)
|
||||
|
||||
+32
-13
@@ -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'<meta name="chaptertitle" content="'+chaptertitle+u'"></meta>',
|
||||
# u'<meta name="chaptertitle" content="">'+chapterorigtitle+u'</meta>')
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user