From e27908e70afc466830cb69486862f312d66bbd0d Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sat, 1 Aug 2020 17:21:19 -0500 Subject: [PATCH] Accept storyUrl with title in it for adapter_webnovelcom. Addresses #520 --- fanficfare/adapters/adapter_webnovelcom.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fanficfare/adapters/adapter_webnovelcom.py b/fanficfare/adapters/adapter_webnovelcom.py index ef853620f..adc75e7a3 100644 --- a/fanficfare/adapters/adapter_webnovelcom.py +++ b/fanficfare/adapters/adapter_webnovelcom.py @@ -73,10 +73,18 @@ def __init__(self, config, url): BaseSiteAdapter.__init__(self, config, url) # get storyId from url # https://www.webnovel.com/book/6831837102000205 - self.story.setMetadata('storyId', self.parsedUrl.path.split('/')[2]) - # normalized story URL. - self._setURL('https://' + self.getSiteDomain() + '/book/' + self.story.getMetadata('storyId')) + m = re.match(self.getSiteURLPattern(),url) + if m: + self.story.setMetadata('storyId',m.group('id')) + # normalized story URL. + title = m.group('title') or "" + self._setURL('https://' + self.getSiteDomain() + '/book/' + title + self.story.getMetadata('storyId')) + else: + raise exceptions.InvalidStoryURL(url, + self.getSiteDomain(), + self.getSiteExampleURLs()) + # Each adapter needs to have a unique site abbreviation. self.story.setMetadata('siteabbrev', 'wncom') @@ -90,10 +98,11 @@ def getSiteDomain(): @classmethod def getSiteExampleURLs(cls): - return 'https://' + cls.getSiteDomain() + '/book/123456789012345' + return 'https://' + cls.getSiteDomain() + '/book/story-title_123456789012345 https://' + cls.getSiteDomain() + '/book/123456789012345' def getSiteURLPattern(self): - return r'https://' + re.escape(self.getSiteDomain()) + r'/book/*(?P\d+)' + # https://www.webnovel.com/book/game-of-thrones%3A-the-prideful-one._17509790806343405 + return r'https://' + re.escape(self.getSiteDomain()) + r'/book/(?P.*_)?(?P<id>\d+)' def use_pagecache(self): '''