From 34b5076753bb99e9d0145ce5723fd83b93748d8e Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Wed, 10 Apr 2013 13:30:05 -0500 Subject: [PATCH] Add 'url' to chapter custom formats and class="skip_on_ffdl_update" for updates. --- calibre-plugin/__init__.py | 1 - fanficdownloader/adapters/base_adapter.py | 6 ++++-- fanficdownloader/epubutils.py | 3 +++ fanficdownloader/story.py | 10 ++++++---- fanficdownloader/writers/base_writer.py | 5 +++-- fanficdownloader/writers/writer_epub.py | 6 +++--- fanficdownloader/writers/writer_html.py | 4 ++-- fanficdownloader/writers/writer_mobi.py | 4 ++-- fanficdownloader/writers/writer_txt.py | 4 ++-- 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index bbcdfb2..dc0a154 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -1,5 +1,4 @@ #!/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) diff --git a/fanficdownloader/adapters/base_adapter.py b/fanficdownloader/adapters/base_adapter.py index 8f051d4..07b2c27 100644 --- a/fanficdownloader/adapters/base_adapter.py +++ b/fanficdownloader/adapters/base_adapter.py @@ -197,7 +197,8 @@ class BaseSiteAdapter(Configurable): for index, (title,url) in enumerate(self.chapterUrls): if (self.chapterFirst!=None and index < self.chapterFirst) or \ (self.chapterLast!=None and index > self.chapterLast): - self.story.addChapter(removeEntities(title), + self.story.addChapter(url, + removeEntities(title), None) else: if self.oldchapters and index < len(self.oldchapters): @@ -206,7 +207,8 @@ class BaseSiteAdapter(Configurable): partial(cachedfetch,self._fetchUrlRaw,self.oldimgs)) else: data = self.getChapterText(url) - self.story.addChapter(removeEntities(title), + self.story.addChapter(url, + removeEntities(title), removeEntities(data)) self.storyDone = True diff --git a/fanficdownloader/epubutils.py b/fanficdownloader/epubutils.py index 9e1c6c9..f75f853 100644 --- a/fanficdownloader/epubutils.py +++ b/fanficdownloader/epubutils.py @@ -130,6 +130,9 @@ def get_update_data(inputio, h2 = soup.find('h2') if h2: h2.extract() + + for skip in soup.findAll(attrs={'class':'skip_on_ffdl_update'}): + skip.extract() soups.append(soup) diff --git a/fanficdownloader/story.py b/fanficdownloader/story.py index 5e548b1..ca13ef9 100644 --- a/fanficdownloader/story.py +++ b/fanficdownloader/story.py @@ -470,11 +470,11 @@ class Story(Configurable): return list(subjectset | set(self.getConfigList("extratags"))) - def addChapter(self, title, html): + def addChapter(self, url, title, html): if self.getConfig('strip_chapter_numbers') and \ self.getConfig('chapter_title_strip_pattern'): title = re.sub(self.getConfig('chapter_title_strip_pattern'),"",title) - self.chapters.append( (title,html) ) + self.chapters.append( (url,title,html) ) def getChapters(self,fortoc=False): "Chapters will be tuples of (title,html)" @@ -484,8 +484,10 @@ class Story(Configurable): (self.getConfig('add_chapter_numbers') == "true" \ or (self.getConfig('add_chapter_numbers') == "toconly" and fortoc)) \ and self.getConfig('chapter_title_add_pattern'): - for index, (title,html) in enumerate(self.chapters): - retval.append( (string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':title}),html) ) + for index, (url,title,html) in enumerate(self.chapters): + retval.append( (url, + string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':title}), + html) ) else: retval = self.chapters diff --git a/fanficdownloader/writers/base_writer.py b/fanficdownloader/writers/base_writer.py index a2d561a..4211de2 100644 --- a/fanficdownloader/writers/base_writer.py +++ b/fanficdownloader/writers/base_writer.py @@ -177,11 +177,12 @@ class BaseStoryWriter(Configurable): self._write(out,START.substitute(self.story.getAllMetadata())) - for index, (title,html) in enumerate(self.story.getChapters(fortoc=True)): + for index, (url,title,html) in enumerate(self.story.getChapters(fortoc=True)): if html: self._write(out,ENTRY.substitute({'chapter':title, 'number':index+1, - 'index':"%04d"%(index+1)})) + 'index':"%04d"%(index+1), + 'url':url})) self._write(out,END.substitute(self.story.getAllMetadata())) diff --git a/fanficdownloader/writers/writer_epub.py b/fanficdownloader/writers/writer_epub.py index ba6ba97..cbf6d3a 100644 --- a/fanficdownloader/writers/writer_epub.py +++ b/fanficdownloader/writers/writer_epub.py @@ -501,7 +501,7 @@ div { margin: 0pt; padding: 0pt; } items.append(("log_page","OEBPS/log_page.xhtml","application/xhtml+xml","Update Log")) itemrefs.append("log_page") - for index, (title,html) in enumerate(self.story.getChapters(fortoc=True)): + for index, (url,title,html) in enumerate(self.story.getChapters(fortoc=True)): if html: i=index+1 items.append(("file%04d"%i, @@ -649,10 +649,10 @@ div { margin: 0pt; padding: 0pt; } else: CHAPTER_END = self.EPUB_CHAPTER_END - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (url,title,html) in enumerate(self.story.getChapters()): if html: logger.debug('Writing chapter text for: %s' % title) - vals={'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} + vals={'url':url, 'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} fullhtml = CHAPTER_START.substitute(vals) + html + CHAPTER_END.substitute(vals) # ffnet(& maybe others) gives the whole chapter text # as one line. This causes problems for nook(at diff --git a/fanficdownloader/writers/writer_html.py b/fanficdownloader/writers/writer_html.py index 0224dfc..41b0175 100644 --- a/fanficdownloader/writers/writer_html.py +++ b/fanficdownloader/writers/writer_html.py @@ -128,10 +128,10 @@ ${output_css} else: CHAPTER_END = self.HTML_CHAPTER_END - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (url,title,html) in enumerate(self.story.getChapters()): if html: logging.debug('Writing chapter text for: %s' % title) - vals={'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} + vals={'url':url, 'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} self._write(out,CHAPTER_START.substitute(vals)) self._write(out,html) self._write(out,CHAPTER_END.substitute(vals)) diff --git a/fanficdownloader/writers/writer_mobi.py b/fanficdownloader/writers/writer_mobi.py index 5da8743..4396ab0 100644 --- a/fanficdownloader/writers/writer_mobi.py +++ b/fanficdownloader/writers/writer_mobi.py @@ -161,10 +161,10 @@ ${value}
else: CHAPTER_END = self.MOBI_CHAPTER_END - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (url,title,html) in enumerate(self.story.getChapters()): if html: logger.debug('Writing chapter text for: %s' % title) - vals={'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} + vals={'url':url, 'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} fullhtml = CHAPTER_START.substitute(vals) + html + CHAPTER_END.substitute(vals) # ffnet(& maybe others) gives the whole chapter text # as one line. This causes problems for nook(at diff --git a/fanficdownloader/writers/writer_txt.py b/fanficdownloader/writers/writer_txt.py index 388d4d4..8705a41 100644 --- a/fanficdownloader/writers/writer_txt.py +++ b/fanficdownloader/writers/writer_txt.py @@ -154,10 +154,10 @@ End file. else: CHAPTER_END = self.TEXT_CHAPTER_END - for index, (title,html) in enumerate(self.story.getChapters()): + for index, (url, title,html) in enumerate(self.story.getChapters()): if html: logging.debug('Writing chapter text for: %s' % title) - vals={'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} + vals={'url':url, 'chapter':title, 'index':"%04d"%(index+1), 'number':index+1} self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_START.substitute(vals))))) self._write(out,self.lineends(html2text(html,wrap_width=self.wrap_width))) self._write(out,self.lineends(self.wraplines(removeAllEntities(CHAPTER_END.substitute(vals)))))