From 2a86c3c9abbcb0286eafd83920b84690add25298 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sun, 15 Jan 2012 23:14:54 -0600 Subject: [PATCH] Adding 'characters' parsing to other existing sites. Similar 'fix' as twiwrite for plugin for some stories across several sites. Suspect different SGMLParser in calibre stumbling on something common to many eFiction sites. --- calibre-plugin/ffdl_plugin.py | 5 +++++ .../adapters/adapter_adastrafanficcom.py | 19 +++++++++++++++- .../adapters/adapter_castlefansorg.py | 6 +++++ .../adapters/adapter_ficwadcom.py | 6 +++++ .../adapter_harrypotterfanfictioncom.py | 5 +++++ .../adapters/adapter_potionsandsnitchesnet.py | 10 +++++++++ fanficdownloader/adapters/adapter_siyecouk.py | 5 ++++- .../adapters/adapter_tenhawkpresentscom.py | 6 +++++ .../adapter_thewriterscoffeeshopcom.py | 19 +++++++++++++++- .../adapters/adapter_twilightednet.py | 21 +++++++++++++++++- .../adapters/adapter_twiwritenet.py | 22 ++++++++++++++----- .../adapters/adapter_whoficcom.py | 9 ++++++++ 12 files changed, 124 insertions(+), 9 deletions(-) diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 0a9a069..d677ea1 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -109,6 +109,11 @@ class FanFictionDownLoaderPlugin(InterfaceAction): self.menus_lock = threading.RLock() + def initialization_complete(self): + # otherwise configured hot keys won't work until the menu's + # been displayed once. + self.rebuild_menus() + def about_to_show_menu(self): self.rebuild_menus() diff --git a/fanficdownloader/adapters/adapter_adastrafanficcom.py b/fanficdownloader/adapters/adapter_adastrafanficcom.py index bc908a2..14fe48e 100644 --- a/fanficdownloader/adapters/adapter_adastrafanficcom.py +++ b/fanficdownloader/adapters/adapter_adastrafanficcom.py @@ -79,6 +79,11 @@ class AdAstraFanficComSiteAdapter(BaseSiteAdapter): if "Content is only suitable for mature adults. May contain explicit language and adult themes. Equivalent of NC-17." in data: raise exceptions.AdultCheckRequired(self.url) + # problems with some stories, but only in calibre. I suspect + # issues with different SGML parsers in python. This is a + # nasty hack, but it works. + data = data[data.index(" ??? wtf? + data = ""+data[data.index(""):] + # use BeautifulSoup HTML parser to make everything easier to find. soup = bs.BeautifulSoup(data) @@ -170,6 +176,12 @@ class TwilightedNetSiteAdapter(BaseSiteAdapter): for cat in catstext: self.story.addToList('category',cat.string) + if 'Characters' in label: + chars = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=characters')) + charstext = [char.string for char in chars] + for char in charstext: + self.story.addToList('characters',char.string) + ## twilighted.net doesn't use genre. # if 'Genre' in label: # genres = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) @@ -197,7 +209,14 @@ class TwilightedNetSiteAdapter(BaseSiteAdapter): logging.debug('Getting chapter text from: %s' % url) - soup = bs.BeautifulStoneSoup(self._fetchUrl(url), + data = self._fetchUrl(url) + # problems with some stories, but only in calibre. I suspect + # issues with different SGML parsers in python. This is a + # nasty hack, but it works. + # twilighted isn't writing ??? wtf? + data = ""+data[data.index(""):] + + soup = bs.BeautifulStoneSoup(data, selfClosingTags=('br','hr')) # otherwise soup eats the br/hr tags. span = soup.find('div', {'id' : 'story'}) diff --git a/fanficdownloader/adapters/adapter_twiwritenet.py b/fanficdownloader/adapters/adapter_twiwritenet.py index 9473d99..871ad9a 100644 --- a/fanficdownloader/adapters/adapter_twiwritenet.py +++ b/fanficdownloader/adapters/adapter_twiwritenet.py @@ -117,10 +117,13 @@ class TwiwriteNetSiteAdapter(BaseSiteAdapter): if "Access denied. This story has not been validated by the adminstrators of this site." in data: raise exceptions.FailedToDownload(self.getSiteDomain() +" says: Access denied. This story has not been validated by the adminstrators of this site.") - + + # problems with some stories, but only in calibre. I suspect + # issues with different SGML parsers in python. This is a + # nasty hack, but it works. + data = data[data.index("]+>','',moremeta) # strip tags.