Dosage Modules

Short introduction and Examples

A Dosage Module is just a Python module. This makes it simple to make modules for most webcomics and makes it possible to create really complex solutions for webcomics with "strange" layouts. Let's start with a simple example (I took Megatokyo which is in the MegaTokyo? module):

import re
from dosage.modules.helpers.BasicComicModule import BasicComicModule

class MegaTokyo(BasicComicModule):
    latestUrl = 'http://www.megatokyo.com/'
    imageUrl = 'http://www.megatokyo.com/index.php?strip_id=%s'
    imageSearch = re.compile(r'<img.+?src="(/strips/.+?)"', re.IGNORECASE)
    prevSearch = re.compile(r"<a.+?href='(/?index.php\?strip_id=\d+?)'><img border=0 src='http://www.megatokyo.com/parts/mt-bottom-prev.gif'", re.IGNORECASE)
    help = 'Index format: nnnn'

We see that the file starts with some Python magic to get the needed modules loaded. Then a new class with the name of our comic is created. This new class is derived from the BasicComicModule? class, which includes all the complicated stuff.

The rest of the file is just a couple of variables which tell Dosage how to retrieve this comic. They are:

  • latestUrl - The home page of the webcomic, the place where the latest comic can be found.
  • imageUrl - A printf template of what the image page URL looks like. This is used when the user specifies a specific comic with "ComicName:234" on the command line. the %s is replaced with the specified comic number.
  • imageSearch - A RegularExpression? matching the image that shows the comic for each day. You must capture the file name with the first set of parenthesis in the RegularExpression?.
  • prevSearch - A RegularExpression? matching the link to the previous comic on every page. Same rules as imageSearch.
  • help - Short help text giving the user a hint how to specify comic numbers.

If your favorite web comic is using a hosting provider like KeenSpot / KeenSpace it is even easier:

  1. Look at the KeenSpot? module.
  2. See the big list of comics? Just add your favorite comic to that list and you are done.

More complex examples

Consider looking at modules like LittleGamers? or KingFeatures? for more complex examples, dealing with things like complicated indexing and custom filenames.

Conversion from other offline webcomic viewers

This is to help ticket #114. Other offline webcomic viewers: