2016-04-01 22:14:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-10-28 22:21:41 +00:00
|
|
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
2016-04-01 22:14:31 +00:00
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
|
|
|
# Copyright (C) 2015-2016 Tobias Gruetzmacher
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
from ..scraper import _ParserScraper
|
2016-05-06 23:50:10 +00:00
|
|
|
from ..helpers import indirectStarter
|
2016-04-01 22:14:31 +00:00
|
|
|
|
|
|
|
# Common base classes for comics with the same structure (same hosting
|
|
|
|
# software, for example) go here. Since those are shared by many modules,
|
|
|
|
# please don't use lists of expression, as that makes it hard to track which
|
|
|
|
# expression is for which comics.
|
|
|
|
|
2016-04-10 21:04:34 +00:00
|
|
|
|
|
|
|
def xpath_class(name):
|
|
|
|
"""Returns an XPath expressions which finds a tag which has a specified
|
|
|
|
class."""
|
|
|
|
return 'contains(concat(" ", @class, " "), " %s ")' % name
|
|
|
|
|
|
|
|
|
|
|
|
WP_LATEST_SEARCH = '//a[%s]' % xpath_class('comic-nav-last')
|
|
|
|
WP_PREV_SEARCH = '//a[%s]' % xpath_class('comic-nav-previous')
|
2016-04-03 20:58:01 +00:00
|
|
|
|
|
|
|
|
2016-04-01 22:14:31 +00:00
|
|
|
class _WordPressScraper(_ParserScraper):
|
|
|
|
imageSearch = '//div[@id="comic"]//img'
|
2016-04-05 21:58:43 +00:00
|
|
|
prevSearch = WP_PREV_SEARCH
|
2016-04-01 22:14:31 +00:00
|
|
|
|
|
|
|
|
2016-05-01 23:25:34 +00:00
|
|
|
class _WPNaviIn(_WordPressScraper):
|
|
|
|
prevSearch = '//a[%s]' % xpath_class('navi-prev-in')
|
|
|
|
|
|
|
|
|
2016-04-03 22:12:53 +00:00
|
|
|
class _ComicControlScraper(_ParserScraper):
|
|
|
|
imageSearch = '//img[@id="cc-comic"]'
|
|
|
|
prevSearch = '//a[@rel="prev"]'
|
2016-05-06 23:50:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class _TumblrScraper(_ParserScraper):
|
|
|
|
starter = indirectStarter
|
|
|
|
|
|
|
|
def namer(self, image_url, page_url):
|
|
|
|
# tumblr URLs: http://host/post/num/name
|
|
|
|
# 0 1 2 3 4 5
|
|
|
|
parts = page_url.split('/')
|
|
|
|
if len(parts) > 5:
|
|
|
|
return '%s_%s' % (parts[4], parts[5])
|
|
|
|
else:
|
|
|
|
return parts[4]
|
|
|
|
|
|
|
|
def shouldSkipUrl(self, url, data):
|
|
|
|
"""Reblogged stuff is iframed"""
|
|
|
|
return data.xpath('//div[@id="post"]//iframe')
|