Shortcuts for config/about for Mac. Handle tags inside metadata on ksarchivecom.

Some Mac versions crash if there are menu items set to not have shortcuts.
Also accept https, but change to http.
This commit is contained in:
Jim Miller 2012-08-27 12:13:31 -05:00
parent 86329a1fe3
commit 347eb69044
4 changed files with 27 additions and 35 deletions

View file

@ -27,7 +27,7 @@ class FanFictionDownLoaderBase(InterfaceActionBase):
description = 'UI plugin to download FanFiction stories from various sites.'
supported_platforms = ['windows', 'osx', 'linux']
author = 'Jim Miller'
version = (1, 6, 6)
version = (1, 6, 7)
minimum_calibre_version = (0, 8, 57)
#: This field defines the GUI plugin class that contains all the code

View file

@ -143,8 +143,6 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
triggered=self.add_dialog )
self.update_action = self.create_menu_item_ex(self.menu, '&Update Existing FanFiction Book(s)', image='plusplus.png',
unique_name='Update Existing FanFiction Book(s)',
shortcut_name='Update Existing FanFiction Book(s)',
triggered=self.update_existing)
if 'Reading List' in self.gui.iactions and (prefs['addtolists'] or prefs['addtoreadlists']) :
@ -164,37 +162,31 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
if addmenutxt:
self.add_send_action = self.create_menu_item_ex(self.menu, addmenutxt, image='plusplus.png',
unique_name=addmenutxt,
shortcut_name=addmenutxt,
triggered=partial(self.update_lists,add=True))
if rmmenutxt:
self.add_remove_action = self.create_menu_item_ex(self.menu, rmmenutxt, image='minusminus.png',
unique_name=rmmenutxt,
shortcut_name=rmmenutxt,
triggered=partial(self.update_lists,add=False))
self.menu.addSeparator()
self.get_list_action = self.create_menu_item_ex(self.menu, 'Get URLs from Selected Books', image='bookmarks.png',
unique_name='Get URLs from Selected Books',
shortcut_name='Get URLs from Selected Books',
triggered=self.get_list_urls)
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,
image= 'config.png',
unique_name='Configure FanFictionDownLoader',
triggered=partial(do_user_config,parent=self.gui))
self.config_action = self.create_menu_item_ex(self.menu, '&Configure Plugin', #shortcut=False, # causes crashes on some Macs.
image= 'config.png',
unique_name='Configure FanFictionDownLoader',
shortcut_name='Configure FanFictionDownLoader',
triggered=partial(do_user_config,parent=self.gui))
self.about_action = create_menu_action_unique(self, self.menu, 'About Plugin', shortcut=False,
image= 'images/icon.png',
unique_name='About FanFictionDownLoader',
triggered=self.about)
self.about_action = self.create_menu_item_ex(self.menu, 'About Plugin', #shortcut=False, # causes crashes on some Macs.
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():
@ -220,12 +212,12 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
def create_menu_item_ex(self, parent_menu, menu_text, image=None, tooltip=None,
shortcut=None, triggered=None, is_checked=None, shortcut_name=None,
unique_name=None):
#print("create_menu_item_ex before %s"%unique_name)
#print("create_menu_item_ex before %s"%menu_text)
ac = create_menu_action_unique(self, parent_menu, menu_text, image, tooltip,
shortcut, triggered, is_checked, shortcut_name, unique_name)
self.actions_unique_map[ac.calibre_shortcut_unique_name] = ac.calibre_shortcut_unique_name
self.menu_actions.append(ac)
#print("create_menu_item_ex after %s"%unique_name)
#print("create_menu_item_ex after %s"%menu_text)
return ac
def plugin_button(self):

View file

@ -117,7 +117,7 @@ for x in imports():
def getAdapter(config,url,fileform=None):
## fix up leading protocol.
fixedurl = re.sub(r"(?i)^[htp]+[:/]+","http://",url.strip())
fixedurl = re.sub(r"(?i)^[htps]+[:/]+","http://",url.strip())
if not fixedurl.startswith("http"):
fixedurl = "http://%s"%url
## remove any trailing '#' locations.

View file

@ -167,7 +167,7 @@ class KSArchiveComAdapter(BaseSiteAdapter): # XXX
a = soup.find('a', href=re.compile(r"viewuser.php\?uid=\d+"))
self.story.setMetadata('authorId',a['href'].split('=')[1])
self.story.setMetadata('authorUrl','http://'+self.host+'/'+a['href'])
self.story.setMetadata('author',a.string)
self.story.setMetadata('author',stripHTML(a))
# Find the chapters:
for chapter in soup.findAll('a', href=re.compile(r'viewstory.php\?sid='+self.story.getMetadata('storyId')+"&chapter=\d+$")):
@ -190,7 +190,7 @@ class KSArchiveComAdapter(BaseSiteAdapter): # XXX
labels = soup.findAll('span',{'class':'label'})
for labelspan in labels:
value = labelspan.nextSibling
label = labelspan.string
label = stripHTML(labelspan)
if 'Summary' in label:
## Everything until the next span class='label'
@ -215,50 +215,50 @@ class KSArchiveComAdapter(BaseSiteAdapter): # XXX
if 'Categories' in label:
cats = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=categories'))
catstext = [cat.string for cat in cats]
catstext = [stripHTML(cat) for cat in cats]
for cat in catstext:
# 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)
self.story.addToList('category',stripHTML(cat))
if 'Characters' in label:
self.story.addToList('characters','Kirk')
self.story.addToList('characters','Spock')
chars = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=characters'))
charstext = [char.string for char in chars]
charstext = [stripHTML(char) for char in chars]
for char in charstext:
self.story.addToList('characters',char.string)
self.story.addToList('characters',stripHTML(char))
## Not all sites use Genre, but there's no harm to
## leaving it in. Check to make sure the type_id number
## is correct, though--it's site specific.
if 'Genre' in label:
genres = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class&type_id=1')) # XXX
genrestext = [genre.string for genre in genres]
genrestext = [stripHTML(genre) for genre in genres]
self.genre = ', '.join(genrestext)
for genre in genrestext:
self.story.addToList('genre',genre.string)
self.story.addToList('genre',stripHTML(genre))
## In addition to Genre (which is very site specific) KSA
## has 'Story Type', which is much more what most sites
## call genre.
if 'Story Type' in label:
genres = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class&type_id=5')) # XXX
genrestext = [genre.string for genre in genres]
genrestext = [stripHTML(genre) for genre in genres]
self.genre = ', '.join(genrestext)
for genre in genrestext:
self.story.addToList('genre',genre.string)
self.story.addToList('genre',stripHTML(genre))
## Not all sites use Warnings, but there's no harm to
## leaving it in. Check to make sure the type_id number
## is correct, though--it's site specific.
if 'Warnings' in label:
warnings = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class&type_id=2')) # XXX
warningstext = [warning.string for warning in warnings]
warningstext = [stripHTML(warning) for warning in warnings]
self.warning = ', '.join(warningstext)
for warning in warningstext:
self.story.addToList('warnings',warning.string)
self.story.addToList('warnings',stripHTML(warning))
if 'Completed' in label:
if 'Yes' in value:
@ -277,7 +277,7 @@ class KSArchiveComAdapter(BaseSiteAdapter): # XXX
try:
# Find Series name from series URL.
a = soup.find('a', href=re.compile(r"viewseries.php\?seriesid=\d+"))
series_name = a.string
series_name = stripHTML(a)
series_url = 'http://'+self.host+'/'+a['href']
# use BeautifulSoup HTML parser to make everything easier to find.