Adding three sites under sinful-dreams.com and 1st version multi-adapter per domain support.

This commit is contained in:
Jim Miller 2017-01-02 13:23:55 -06:00
parent 083ad59c28
commit caacd1bc0c
6 changed files with 159 additions and 11 deletions

View file

@ -165,6 +165,9 @@ import adapter_trekfanfictionnet
import adapter_wuxiaworldcom
import adapter_wwwlushstoriescom
import adapter_wwwutopiastoriescom
import adapter_sinfuldreamscomunicornfic
import adapter_sinfuldreamscomwhisperedmuse
import adapter_sinfuldreamscomwickedtemptation
## This bit of complexity allows adapters to be added by just adding
## importing. It eliminates the long if/else clauses we used to need
@ -185,7 +188,9 @@ for x in imports():
cls = sys.modules[x].getClass()
__class_list.append(cls)
for site in cls.getAcceptDomains():
__domain_map[site]=cls
l = __domain_map.get(site,[])
l.append(cls)
__domain_map[site]=l
def getNormalStoryURL(url):
r = getNormalStoryURLSite(url)
@ -215,7 +220,7 @@ getNormalStoryURL.__dummyconfig = None
def getAdapter(config,url,anyurl=False):
#logger.debug("trying url:"+url)
(cls,fixedurl) = getClassFor(url)
(cls,fixedurl) = _get_class_for(url)
#logger.debug("fixedurl:"+fixedurl)
if cls:
if anyurl:
@ -251,14 +256,14 @@ def getSiteExamples():
return l
def getConfigSectionsFor(url):
(cls,fixedurl) = getClassFor(url)
(cls,fixedurl) = _get_class_for(url)
if cls:
return cls.getConfigSections()
# No adapter found.
raise exceptions.UnknownSite( url, [cls.getSiteDomain() for cls in __class_list] )
def getClassFor(url):
def _get_class_for(url):
## fix up leading protocol.
fixedurl = re.sub(r"(?i)^[htp]+(s?)[:/]+",r"http\1://",url.strip())
if fixedurl.startswith("//"):
@ -276,23 +281,34 @@ def getClassFor(url):
if( domain != parsedUrl.netloc ):
fixedurl = fixedurl.replace(parsedUrl.netloc,domain)
cls = getClassFromList(domain)
if not cls and domain.startswith("www."):
clslst = _get_classlist_fromlist(domain)
## assumes all adapters for a domain will have www or not have www
## but not mixed.
if not clslst and domain.startswith("www."):
domain = domain.replace("www.","")
#logger.debug("trying site:without www: "+domain)
cls = getClassFromList(domain)
clslst = _get_classlist_fromlist(domain)
fixedurl = re.sub(r"^http(s?)://www\.",r"http\1://",fixedurl)
if not cls:
if not clslst:
#logger.debug("trying site:www."+domain)
cls = getClassFromList("www."+domain)
clslst =_get_classlist_fromlist("www."+domain)
fixedurl = re.sub(r"^http(s?)://",r"http\1://www.",fixedurl)
cls = None
if len(clslst) == 1:
cls = clslst[0]
elif len(clslst) > 1:
for c in clslst:
if c.getSiteURLFragment() in fixedurl:
cls = c
break
if cls:
fixedurl = cls.stripURLParameters(fixedurl)
return (cls,fixedurl)
def getClassFromList(domain):
def _get_classlist_fromlist(domain):
try:
return __domain_map[domain]
except KeyError:

View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Copyright 2011 Fanficdownloader team, 2017 FanFicFare team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Software: eFiction
from base_efiction_adapter import BaseEfictionAdapter
class SinfulDreamsComUnicornFic(BaseEfictionAdapter):
@staticmethod
def getSiteDomain():
return 'sinful-dreams.com'
@classmethod
def getPathToArchive(self):
return '/unicorn/fic'
@classmethod
def getSiteAbbrev(self):
return 'snfldrms-uf'
@classmethod
def getDateFormat(self):
return "%m/%d/%Y"
def getClass():
return SinfulDreamsComUnicornFic

View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Copyright 2011 Fanficdownloader team, 2017 FanFicFare team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Software: eFiction
from base_efiction_adapter import BaseEfictionAdapter
class SinfulDreamsComWhisperedMuse(BaseEfictionAdapter):
@staticmethod
def getSiteDomain():
return 'sinful-dreams.com'
@classmethod
def getPathToArchive(self):
return '/whispered/muse'
@classmethod
def getSiteAbbrev(self):
return 'snfldrms-wm'
@classmethod
def getDateFormat(self):
return "%m/%d/%Y"
def getClass():
return SinfulDreamsComWhisperedMuse

View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Copyright 2011 Fanficdownloader team, 2017 FanFicFare team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Software: eFiction
from base_efiction_adapter import BaseEfictionAdapter
class SinfulDreamsComWickedTemptation(BaseEfictionAdapter):
@staticmethod
def getSiteDomain():
return 'sinful-dreams.com'
@classmethod
def getPathToArchive(self):
return '/wicked/temptation'
@classmethod
def getSiteAbbrev(self):
return 'snfldrms-wt'
@classmethod
def getDateFormat(self):
return "%m/%d/%Y"
def getClass():
return SinfulDreamsComWickedTemptation

View file

@ -476,6 +476,11 @@ class BaseSiteAdapter(Configurable):
"Needs to be overriden in each adapter class."
return 'no such domain'
@classmethod
def getSiteURLFragment(self):
"Needs to be overriden in case of adapters that share a domain."
return self.getSiteDomain()
@classmethod
def getConfigSection(cls):
"Only needs to be overriden if != site domain."

View file

@ -73,7 +73,7 @@ class BaseEfictionAdapter(BaseSiteAdapter):
@classmethod
def getConfigSections(cls):
"Only needs to be overriden if has additional ini sections."
return ['base_efiction',cls.getConfigSection()]
return ['base_efiction',cls.getConfigSection(),cls.getSiteDomain()+cls.getPathToArchive()]
@classmethod
def getAcceptDomains(cls):
@ -87,6 +87,10 @@ class BaseEfictionAdapter(BaseSiteAdapter):
def getSiteURLPattern(self):
return r"https?://(www\.)?%s%s/%s\?sid=(?P<storyId>\d+)" % (self.getSiteDomain(), self.getPathToArchive(), self.getViewStoryPhpName())
@classmethod
def getSiteURLFragment(self):
return self.getSiteDomain()+self.getPathToArchive()
@classmethod
def getEncoding(cls):
"""