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:
parent
e5c1b1879b
commit
076a12f4e5
7 changed files with 48 additions and 177 deletions
|
|
@ -17,74 +17,18 @@
|
|||
# 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 __future__ import with_statement
|
||||
|
||||
import re
|
||||
|
||||
from weboob.capabilities.gallery import ICapGallery, BaseGallery, BaseImage
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.browser import BaseBrowser, BasePage
|
||||
from ..genericcomicreader.backend import GenericComicReaderBackend, DisplayPage
|
||||
|
||||
__all__ = ['SimplyreaditBackend']
|
||||
|
||||
class DisplayPage(BasePage):
|
||||
def get_page(self, gallery):
|
||||
src = self.document.xpath("//img[@class='open']/@src")[0]
|
||||
|
||||
return BaseImage(src,
|
||||
gallery=gallery,
|
||||
url=src)
|
||||
|
||||
def page_list(self):
|
||||
return self.document.xpath("(//div[contains(@class,'dropdown_right')]/ul[@class='dropdown'])[1]/li/a/@href")
|
||||
|
||||
class SimplyreaditBrowser(BaseBrowser):
|
||||
PAGES = { r'http://.+\.simplyread.it/reader/read/.+': DisplayPage }
|
||||
|
||||
def iter_gallery_images(self, gallery):
|
||||
self.location(gallery.url)
|
||||
assert self.is_on_page(DisplayPage)
|
||||
|
||||
for p in self.page.page_list():
|
||||
self.location(p)
|
||||
assert self.is_on_page(DisplayPage)
|
||||
yield self.page.get_page(gallery)
|
||||
|
||||
def fill_image(self, image, fields):
|
||||
if 'data' in fields:
|
||||
image.data = self.readurl(image.url)
|
||||
|
||||
class SimplyreaditBackend(BaseBackend, ICapGallery):
|
||||
class SimplyreaditBackend(GenericComicReaderBackend):
|
||||
NAME = 'simplyreadit'
|
||||
MAINTAINER = 'Noé Rubinstein'
|
||||
EMAIL = 'noe.rubinstein@gmail.com'
|
||||
VERSION = '0.9'
|
||||
DESCRIPTION = 'Simplyread.it'
|
||||
LICENSE = 'AGPLv3+'
|
||||
BROWSER = SimplyreaditBrowser
|
||||
|
||||
def iter_gallery_images(self, gallery):
|
||||
with self.browser:
|
||||
return self.browser.iter_gallery_images(gallery)
|
||||
|
||||
def get_gallery(self, _id):
|
||||
match = re.match(r'(?:(?:.+symplyread.it/reader/read/)?/)?([^/]+(?:/[^/]+)*)', _id)
|
||||
if match is None:
|
||||
return None
|
||||
|
||||
_id = match.group(1)
|
||||
|
||||
gallery = BaseGallery(_id, url=('http://www.simplyread.it/reader/read/%s' % _id))
|
||||
with self.browser:
|
||||
return gallery
|
||||
|
||||
def fill_gallery(self, gallery, fields):
|
||||
gallery.title = gallery.id
|
||||
|
||||
def fill_image(self, image, fields):
|
||||
with self.browser:
|
||||
self.browser.fill_image(image, fields)
|
||||
|
||||
OBJECTS = {
|
||||
BaseGallery: fill_gallery,
|
||||
BaseImage: fill_image }
|
||||
DESCRIPTION = 'Simplyreadit manga reading site'
|
||||
BROWSER_PARAMS = dict(
|
||||
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'.+simplyread.it/reader/read/(%s)/page/.+' % ID_REGEXP
|
||||
PAGES = { r'http://.+\.simplyread.it/reader/read/.+': DisplayPage }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue