Add event comicPageLink for every previous link.

This event allows a listener to build connections between pages.
This commit is contained in:
Tobias Gruetzmacher 2013-03-10 16:23:04 +01:00
parent 9f08b21a7e
commit 0a218c0283
2 changed files with 11 additions and 0 deletions

View file

@ -38,6 +38,10 @@ class EventHandler(object):
"""Emit a comic downloaded event. Should be overridden in subclass.""" """Emit a comic downloaded event. Should be overridden in subclass."""
pass pass
def comicPageLink(self, comic, url, prevUrl):
"""Emit an event to inform the handler about links between comic pages. Should be overridden in subclass."""
pass
def end(self): def end(self):
"""Emit an end event. Should be overridden in subclass.""" """Emit an end event. Should be overridden in subclass."""
pass pass
@ -216,6 +220,11 @@ class MultiHandler(object):
for handler in _handlers: for handler in _handlers:
handler.comicDownloaded(comic, filename) handler.comicDownloaded(comic, filename)
def comicPageLink(self, comic, url, prevUrl):
"""Emit an event to inform the handler about links between comic pages. Should be overridden in subclass."""
for handler in _handlers:
handler.comicPageLink(comic, url, prevUrl)
def end(self): def end(self):
"""Emit an end event. Should be overridden in subclass.""" """Emit an end event. Should be overridden in subclass."""
for handler in _handlers: for handler in _handlers:

View file

@ -7,6 +7,7 @@ from . import loader
from .util import fetchUrl, fetchUrls, getPageContent from .util import fetchUrl, fetchUrls, getPageContent
from .comic import ComicStrip from .comic import ComicStrip
from .output import out from .output import out
from .events import getHandler
class _BasicScraper(object): class _BasicScraper(object):
@ -161,6 +162,7 @@ class _BasicScraper(object):
else: else:
prevUrl = self.prevUrlModifier(prevUrl) prevUrl = self.prevUrlModifier(prevUrl)
out.debug("Matched previous URL %s" % prevUrl) out.debug("Matched previous URL %s" % prevUrl)
getHandler().comicPageLink(self.getName(), url, prevUrl)
return prevUrl return prevUrl
def getIndexStripUrl(self, index): def getIndexStripUrl(self, index):