diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 307ff75..c5f1e46 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -22,8 +22,9 @@ from calibre.gui2.ui import get_gui from calibre_plugins.fanfictiondownloader_plugin.dialogs \ import (UPDATE, UPDATEALWAYS, OVERWRITE, collision_order, RejectListDialog, EditTextDialog) - -from calibre_plugins.fanfictiondownloader_plugin.fanficdownloader.adapters import getConfigSections + +from calibre_plugins.fanfictiondownloader_plugin.fanficdownloader.adapters \ + import (getConfigSections, getNormalStoryURL) from calibre_plugins.fanfictiondownloader_plugin.common_utils \ import ( get_library_uuid, KeyboardConfigDialog, PrefsViewerDialog ) @@ -159,7 +160,9 @@ class RejectURLList: (rejurl,note) = line.split(',',1) else: (rejurl,note) = (line,'') - cache[rejurl] = note + rejurl = getNormalStoryURL(rejurl) + if rejurl: + cache[rejurl] = note return cache @@ -549,8 +552,8 @@ class BasicTab(QWidget): "", icon=self.windowIcon(), title="Add Reject URLs", - label="Add Reject URLs. Use: 'http://...,note'", - tooltip="One URL per line, everything after ',' will be put in the note.") + label="Add Reject URLs. Use: http://...,note", + tooltip="One URL per line, everything after , will be put in the note.") d.exec_() if d.result() == d.Accepted: rejecturllist.add_text(d.get_plain_text()) diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 2d65924..4597c73 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -1408,20 +1408,7 @@ make_firstimage_cover:true return None def _is_good_downloader_url(self,url): - # this is the accepted way to 'check for existance of a class variable'? really? - try: - self.dummyconfig - except AttributeError: - self.dummyconfig = Configuration("test1.com","EPUB") - # pulling up an adapter is pretty low over-head. If - # it fails, it's a bad url. - try: - adapter = adapters.getAdapter(self.dummyconfig,url) - url = adapter.url - del adapter - return url - except: - return None; + return adapters.getNormalStoryURL(url) def get_url_list(urls): def f(x): diff --git a/fanficdownloader/adapters/__init__.py b/fanficdownloader/adapters/__init__.py index 011c5b4..7d3117e 100644 --- a/fanficdownloader/adapters/__init__.py +++ b/fanficdownloader/adapters/__init__.py @@ -23,6 +23,7 @@ import urlparse as up logger = logging.getLogger(__name__) from .. import exceptions as exceptions +from ..configurable import Configuration ## must import each adapter here. @@ -125,6 +126,22 @@ for x in imports(): #print x __class_list.append(sys.modules[x].getClass()) +def getNormalStoryURL(url): + if not getNormalStoryURL.__dummyconfig: + getNormalStoryURL.__dummyconfig = Configuration("test1.com","EPUB") + # pulling up an adapter is pretty low over-head. If + # it fails, it's a bad url. + try: + adapter = getAdapter(getNormalStoryURL.__dummyconfig,url) + url = adapter.url + del adapter + return url + except: + return None; + +# kludgey function static/singleton +getNormalStoryURL.__dummyconfig = None + def getAdapter(config,url): logger.debug("trying url:"+url)