dosage/dosagelib/plugins/x.py

35 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: iso-8859-1 -*-
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
2014-01-05 16:50:57 +01:00
# Copyright (C) 2012-2014 Bastian Kleineidam
2012-11-21 21:57:26 +01:00
2012-06-20 21:58:13 +02:00
from re import compile
2012-10-11 12:03:12 +02:00
from ..scraper import _BasicScraper
from ..helpers import bounceStarter
2012-11-26 07:13:32 +01:00
from ..util import tagre
2012-10-11 12:03:12 +02:00
2012-06-20 21:58:13 +02:00
class xkcd(_BasicScraper):
url = 'http://xkcd.com/'
starter = bounceStarter(url, compile(tagre("a", "href", r'(/\d+/)', before="next")))
stripUrl = url + '%s/'
2013-04-10 23:57:09 +02:00
firstStripUrl = stripUrl % '1'
2012-11-26 07:13:32 +01:00
imageSearch = compile(tagre("img", "src", r'(http://imgs\.xkcd\.com/comics/[^"]+)'))
prevSearch = compile(tagre("a", "href", r'(/\d+/)', before="prev"))
2012-06-20 21:58:13 +02:00
help = 'Index format: n (unpadded)'
2013-04-13 08:00:03 +02:00
description = u'A webcomic of romance, sarcasm, math, and language.'
2013-12-05 18:29:15 +01:00
textSearch = compile(tagre("img", "title", r'([^"]+)', before=r'http://imgs\.xkcd\.com/comics/'))
2013-04-29 07:19:58 +02:00
adult = True
2012-06-20 21:58:13 +02:00
@classmethod
def namer(cls, imageUrl, pageUrl):
2012-11-26 07:13:32 +01:00
index = int(pageUrl.rstrip('/').rsplit('/', 1)[-1])
name = imageUrl.rsplit('/', 1)[-1].split('.')[0]
return '%03d-%s' % (index, name)
2013-12-04 17:56:54 +01:00
@classmethod
def imageUrlModifier(cls, url, data):
if url and '/large/' in data:
return url.replace(".png", "_large.png")
return url