Handle empty category tags in ksarchive.com, more forgiving 'list from url'.

This commit is contained in:
Jim Miller
2012-07-09 13:12:21 -05:00
parent 6c0b31b2ea
commit f073c2543f
3 changed files with 19 additions and 13 deletions
+9 -9
View File
@@ -193,10 +193,10 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
shortcut_name='Get URLs from Selected Books',
triggered=self.get_list_urls)
self.get_list_action = self.create_menu_item_ex(self.menu, 'Get Story URLs from Web Page', image='view.png',
unique_name='Get Story URLs from Web Page',
shortcut_name='Get Story URLs from Web Page',
triggered=self.get_urls_from_page)
self.get_list_url_action = self.create_menu_item_ex(self.menu, 'Get Story URLs from Web Page', image='view.png',
unique_name='Get Story URLs from Web Page',
shortcut_name='Get Story URLs from Web Page',
triggered=self.get_urls_from_page)
self.menu.addSeparator()
self.config_action = create_menu_action_unique(self, self.menu, '&Configure Plugin', shortcut=False,
@@ -205,11 +205,11 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
shortcut_name='Configure FanFictionDownLoader',
triggered=partial(do_user_config,parent=self.gui))
self.config_action = create_menu_action_unique(self, self.menu, '&About Plugin', shortcut=False,
image= 'images/icon.png',
unique_name='About FanFictionDownLoader',
shortcut_name='About FanFictionDownLoader',
triggered=self.about)
self.about_action = create_menu_action_unique(self, self.menu, '&About Plugin', shortcut=False,
image= 'images/icon.png',
unique_name='About FanFictionDownLoader',
shortcut_name='About FanFictionDownLoader',
triggered=self.about)
# Before we finalize, make sure we delete any actions for menus that are no longer displayed
for menu_id, unique_name in self.old_actions_unique_map.iteritems():
@@ -211,7 +211,9 @@ class KSArchiveComAdapter(BaseSiteAdapter): # XXX
cats = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=categories'))
catstext = [cat.string for cat in cats]
for cat in catstext:
if cat.string.strip() in ('Poetry','Essays'):
# ran across one story with an empty <a href="browse.php?type=categories&amp;catid=1"></a>
# tag in the desc once.
if cat and cat.strip() in ('Poetry','Essays'):
self.story.addToList('category',cat.string)
if 'Characters' in label:
+7 -3
View File
@@ -37,11 +37,15 @@ def get_urls_from_page(url):
for a in soup.findAll('a'):
if a.has_key('href'):
href = form_url(url,a['href'])
# lots of eFiction sites use similar 'are you old enough' javascript links.
if 'javascript' in a['href'] and 'viewstory.php' in a['href']:
m = re.search(r"'(?P<sid>(view)?story\.php\?(sid|psid|no|story|stid)=\d+)",a['href'])
# this (should) catch normal story links, some javascript
# 'are you old enough' links, and 'Report This' links.
# The 'normalized' set prevents duplicates.
if 'story.php' in a['href']:
#print("trying:%s"%a['href'])
m = re.search(r"(?P<sid>(view)?story\.php\?(sid|psid|no|story|stid)=\d+)",a['href'])
if m != None:
href = form_url(url,m.group('sid'))
try:
href = href.replace('&index=1','')
adapter = adapters.getAdapter(config,href,"EPUB")