dosage/dosagelib/plugins/x.py

39 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2016-10-28 22:21:41 +00:00
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
2014-01-05 15:50:57 +00:00
# Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2015-2020 Tobias Gruetzmacher
# Copyright (C) 2019-2020 Daniel Ring
from __future__ import absolute_import, division, print_function
2012-11-21 20:57:26 +00:00
2016-08-18 09:28:25 +00:00
from ..scraper import _ParserScraper
2012-10-11 10:03:12 +00:00
from ..helpers import bounceStarter
2012-06-20 19:58:13 +00:00
2017-05-14 22:54:02 +00:00
2016-08-18 09:28:25 +00:00
class Xkcd(_ParserScraper):
2016-04-05 22:47:47 +00:00
name = 'xkcd'
url = 'https://xkcd.com/'
starter = bounceStarter
stripUrl = url + '%s/'
2013-04-10 21:57:09 +00:00
firstStripUrl = stripUrl % '1'
2019-12-05 06:10:49 +00:00
imageSearch = '//div[@id="comic"]//img'
2016-08-18 09:28:25 +00:00
prevSearch = '//a[@rel="prev"]'
nextSearch = '//a[@rel="next"]'
2012-06-20 19:58:13 +00:00
help = 'Index format: n (unpadded)'
2019-12-05 06:10:49 +00:00
textSearch = '//div[@id="comic"]//img/@title'
2012-06-20 19:58:13 +00:00
def namer(self, image_url, page_url):
2016-04-05 22:47:47 +00:00
index = int(page_url.rstrip('/').rsplit('/', 1)[-1])
name = image_url.rsplit('/', 1)[-1].split('.')[0]
2012-11-26 06:13:32 +00:00
return '%03d-%s' % (index, name)
2013-12-04 16:56:54 +00:00
def imageUrlModifier(self, url, data):
2013-12-04 16:56:54 +00:00
if url and '/large/' in data:
return url.replace(".png", "_large.png")
return url
2016-04-05 22:47:47 +00:00
def shouldSkipUrl(self, url, data):
return url in (
self.stripUrl % '1663', # Garden
)