fix factorization of comic readers

there is still a race condition during the selection of the comic reader
class; sometimes, the URL matches for mangatoshokan but for some reason
mangafox is choosen instead
This commit is contained in:
Noé Rubinstein 2011-08-30 10:18:26 +02:00 committed by Romain Bignon
commit 076a12f4e5
7 changed files with 48 additions and 177 deletions

View file

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Noé Rubinstein
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .mangafox import MangafoxBackend
__all__ = ['MangafoxBackend', 'MangatoshokanBackend', 'SimplyreaditBackend']

View file

@ -29,19 +29,19 @@ __all__ = ['GenericComicReaderBackend']
class DisplayPage(BasePage):
def get_page(self, gallery):
src = self.document.xpath(self.backend.IMG_SRC_XPATH)[0]
src = self.document.xpath(self.browser.params['img_src_xpath'])[0]
return BaseImage(src,
gallery=gallery,
url=src)
def page_list(self):
return self.document.xpath(self.backend.PAGE_LIST_XPATH)
return self.document.xpath(self.browser.params['page_list_xpath'])
class GenericComicReaderBrowser(BaseBrowser):
def __init__(self, *args, **kwargs):
self.PAGES = self.backend.PAGES
def __init__(self, browser_params, *args, **kwargs):
self.params = browser_params
BaseBrowser.__init__(self, *args, **kwargs)
def iter_gallery_images(self, gallery):
@ -49,7 +49,7 @@ class GenericComicReaderBrowser(BaseBrowser):
assert self.is_on_page(DisplayPage)
for p in self.page.page_list():
self.location(self.backend.PAGE_LOCATION % p)
self.location(self.params['page_to_location'] % p)
assert self.is_on_page(DisplayPage)
yield self.page.get_page(gallery)
@ -67,6 +67,11 @@ class GenericComicReaderBackend(BaseBackend, ICapGallery):
LICENSE = 'AGPLv3+'
BROWSER = GenericComicReaderBrowser
def create_default_browser(self):
b = self.create_browser(self.BROWSER_PARAMS)
b.PAGES = self.PAGES
return b
def iter_gallery_images(self, gallery):
with self.browser:
return self.browser.iter_gallery_images(gallery)
@ -82,7 +87,7 @@ class GenericComicReaderBackend(BaseBackend, ICapGallery):
else:
return None
gallery = BaseGallery(_id, url=(self.ID_TO_URL % _id))
with self.browser:
return gallery

View file

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Noé Rubinstein
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .backend import GenericComicReaderBackend, DisplayPage
__all__ = ['MangafoxBackend']
class MangafoxBackend(GenericComicReaderBackend):
NAME = 'mangafox'
DESCRIPTION = 'Mangafox manga reading site'
IMG_SRC_XPATH = "//img[@id='image']/attribute::src"
PAGE_LIST_XPATH = "(//select[@onchange='change_page(this)'])[1]/option/@value"
PAGE_TO_LOCATION = "%s.html"
ID_TO_URL = 'http://www.mangafox.com/manga/%s'
ID_REGEXP = r'/?[^/]+/[^/]+(?:/[^/]+)?/?'
URL_REGEXP = r'.+mangafox.com/manga/(%s).+' % ID_REGEXP
PAGES = { r'http://.+\.mangafox.\w+/manga/[^/]+/[^/]+/([^/]+/)?.+\.html': DisplayPage }

View file

@ -1,34 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Noé Rubinstein
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .backend import GenericComicReaderBackend, DisplayPage
__all__ = ['MangatoshokanBackend']
class MangatoshokanBackend(GenericComicReaderBackend):
NAME = 'mangatoshokan'
DESCRIPTION = 'Mangatoshokan manga reading site'
DOMAIN = "www.mangatoshokan.com"
IMG_SRC_XPATH = "//img[@id='readerPage']/@src"
PAGE_LIST_XPATH = "(//select[@class='headerSelect'])[1]/option/@value"
PAGE_TO_LOCATION = 'http://%s%%s' % DOMAIN
ID_TO_URL = 'http://www.mangatoshokan.com/read/%s'
ID_REGEXP = r'[^/]+(?:/[^/]+)*'
URL_REGEXP = r'.+mangatoshokan.com/read/(%s).+' % ID_REGEXP
PAGES = { r'http://.+\.mangatoshokan.com/read/.+': DisplayPage }

View file

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2011 Noé Rubinstein
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .backend import GenericComicReaderBackend, DisplayPage
__all__ = ['SimplyreaditBackend']
class SimplyreaditBackend(GenericComicReaderBackend):
NAME = 'simplyreadit'
DESCRIPTION = 'Simplyreadit manga reading site'
IMG_SRC_XPATH = "//img[@class='open']/@src"
PAGE_LIST_XPATH = "(//div[contains(@class,'dropdown_right')]/ul[@class='dropdown'])[1]/li/a/@href"
PAGE_TO_LOCATION = "%s"
ID_TO_URL = 'http://www.simplyread.it/reader/read/%s'
ID_REGEXP = r'[^/]+(?:/[^/]+)*'
URL_REGEXP = r'.+symplyread.it/reader/read/(%s)' % ID_REGEXP
PAGES = { r'http://.+\.simplyread.it/reader/read/.+': DisplayPage }