Skip non-image on xkcd.

This commit is contained in:
Tobias Gruetzmacher 2016-04-06 00:47:47 +02:00
parent 9feaf245f2
commit 183d18e7bc

View file

@ -9,20 +9,24 @@ from ..helpers import bounceStarter
from ..util import tagre from ..util import tagre
class xkcd(_BasicScraper): class Xkcd(_BasicScraper):
name = 'xkcd'
url = 'http://xkcd.com/' url = 'http://xkcd.com/'
starter = bounceStarter(url, compile(tagre("a", "href", r'(/\d+/)', before="next"))) starter = bounceStarter(url, compile(tagre("a", "href", r'(/\d+/)',
before="next")))
stripUrl = url + '%s/' stripUrl = url + '%s/'
firstStripUrl = stripUrl % '1' firstStripUrl = stripUrl % '1'
imageSearch = compile(tagre("img", "src", r'(//imgs\.xkcd\.com/comics/[^"]+)')) imageSearch = compile(tagre("img", "src",
r'(//imgs\.xkcd\.com/comics/[^"]+)'))
prevSearch = compile(tagre("a", "href", r'(/\d+/)', before="prev")) prevSearch = compile(tagre("a", "href", r'(/\d+/)', before="prev"))
help = 'Index format: n (unpadded)' help = 'Index format: n (unpadded)'
textSearch = compile(tagre("img", "title", r'([^"]+)', before=r'//imgs\.xkcd\.com/comics/')) textSearch = compile(tagre("img", "title", r'([^"]+)',
before=r'//imgs\.xkcd\.com/comics/'))
@classmethod @classmethod
def namer(cls, imageUrl, pageUrl): def namer(cls, image_url, page_url):
index = int(pageUrl.rstrip('/').rsplit('/', 1)[-1]) index = int(page_url.rstrip('/').rsplit('/', 1)[-1])
name = imageUrl.rsplit('/', 1)[-1].split('.')[0] name = image_url.rsplit('/', 1)[-1].split('.')[0]
return '%03d-%s' % (index, name) return '%03d-%s' % (index, name)
@classmethod @classmethod
@ -30,3 +34,8 @@ class xkcd(_BasicScraper):
if url and '/large/' in data: if url and '/large/' in data:
return url.replace(".png", "_large.png") return url.replace(".png", "_large.png")
return url return url
def shouldSkipUrl(self, url, data):
return url in (
self.stripUrl % '1663', # Garden
)