From 7dae1140a74a239ff7e74c0ee596beb3f1e2679e Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 14 Mar 2014 14:04:15 -0500 Subject: [PATCH] Add exclude_notes option for AO3 to exclude the various notes. --- defaults.ini | 6 ++ .../adapters/adapter_archiveofourownorg.py | 60 +++++++++++-------- plugin-defaults.ini | 6 ++ 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/defaults.ini b/defaults.ini index bbb5ba1..eabdc1c 100644 --- a/defaults.ini +++ b/defaults.ini @@ -573,6 +573,12 @@ include_in_freefromtags:freeformtags ## adds to include_subject_tags instead of replacing it. #extra_subject_tags:fandoms,freeformtags,ao3categories +## AO3 chapters can include several different types of notes. We've +## traditional included them all in the chapter text, but this allows +## you to customize which you include. Copy this parameter to your +## personal.ini and list the ones you don't want. +#exclude_notes:authorheadnotes,chaptersummary,chapterheadnotes,chapterfootnotes,authorfootnotes + [ashwinder.sycophanthex.com] ## Some sites require login (or login for some rated stories) The ## program can prompt you, or you can save it in config. In diff --git a/fanficdownloader/adapters/adapter_archiveofourownorg.py b/fanficdownloader/adapters/adapter_archiveofourownorg.py index 1abaa75..2eda30d 100644 --- a/fanficdownloader/adapters/adapter_archiveofourownorg.py +++ b/fanficdownloader/adapters/adapter_archiveofourownorg.py @@ -321,25 +321,31 @@ class ArchiveOfOurOwnOrgAdapter(BaseSiteAdapter): chapter=bs.BeautifulSoup('
').find('div') data = self._fetchUrl(url) soup = bs.BeautifulSoup(data,selfClosingTags=('br','hr')) - - headnotes = soup.find('div', {'class' : "preface group"}).find('div', {'class' : "notes module"}) - if headnotes != None: - headnotes = headnotes.find('blockquote', {'class' : "userstuff"}) + + exclude_notes=self.getConfigList('exclude_notes') + + if 'authorheadnotes' not in exclude_notes: + headnotes = soup.find('div', {'class' : "preface group"}).find('div', {'class' : "notes module"}) if headnotes != None: - chapter.append("Author's Note:") - chapter.append(headnotes) + headnotes = headnotes.find('blockquote', {'class' : "userstuff"}) + if headnotes != None: + chapter.append("Author's Note:") + chapter.append(headnotes) - chapsumm = soup.find('div', {'id' : "summary"}) - if chapsumm != None: - chapsumm = chapsumm.find('blockquote') - chapter.append("Summary for the Chapter:") - chapter.append(chapsumm) - chapnotes = soup.find('div', {'id' : "notes"}) - if chapnotes != None: - chapnotes = chapnotes.find('blockquote') + if 'chaptersummary' not in exclude_notes: + chapsumm = soup.find('div', {'id' : "summary"}) + if chapsumm != None: + chapsumm = chapsumm.find('blockquote') + chapter.append("Summary for the Chapter:") + chapter.append(chapsumm) + + if 'chapterheadnotes' not in exclude_notes: + chapnotes = soup.find('div', {'id' : "notes"}) if chapnotes != None: - chapter.append("Notes for the Chapter:") - chapter.append(chapnotes) + chapnotes = chapnotes.find('blockquote') + if chapnotes != None: + chapter.append("Notes for the Chapter:") + chapter.append(chapnotes) text = soup.find('div', {'class' : "userstuff module"}) chtext = text.find('h3', {'class' : "landmark heading"}) @@ -347,17 +353,19 @@ class ArchiveOfOurOwnOrgAdapter(BaseSiteAdapter): chtext.extract() chapter.append(text) - chapfoot = soup.find('div', {'class' : "end notes module", 'role' : "complementary"}) - if chapfoot != None: - chapfoot = chapfoot.find('blockquote') - chapter.append("Notes for the Chapter:") - chapter.append(chapfoot) + if 'chapterfootnotes' not in exclude_notes: + chapfoot = soup.find('div', {'class' : "end notes module", 'role' : "complementary"}) + if chapfoot != None: + chapfoot = chapfoot.find('blockquote') + chapter.append("Notes for the Chapter:") + chapter.append(chapfoot) - footnotes = soup.find('div', {'id' : "work_endnotes"}) - if footnotes != None: - footnotes = footnotes.find('blockquote') - chapter.append("Author's Note:") - chapter.append(footnotes) + if 'authorfootnotes' not in exclude_notes: + footnotes = soup.find('div', {'id' : "work_endnotes"}) + if footnotes != None: + footnotes = footnotes.find('blockquote') + chapter.append("Author's Note:") + chapter.append(footnotes) if None == soup: raise exceptions.FailedToDownload("Error downloading Chapter: %s! Missing required element!" % url) diff --git a/plugin-defaults.ini b/plugin-defaults.ini index fcdbade..e100989 100644 --- a/plugin-defaults.ini +++ b/plugin-defaults.ini @@ -542,6 +542,12 @@ include_in_freefromtags:freeformtags ## adds to include_subject_tags instead of replacing it. #extra_subject_tags:fandoms,freeformtags,ao3categories +## AO3 chapters can include several different types of notes. We've +## traditional included them all in the chapter text, but this allows +## you to customize which you include. Copy this parameter to your +## personal.ini and list the ones you don't want. +#exclude_notes:authorheadnotes,chaptersummary,chapterheadnotes,chapterfootnotes,authorfootnotes + [ashwinder.sycophanthex.com] ## Some sites require login (or login for some rated stories) The ## program can prompt you, or you can save it in config. In