2017-05-18 22:31:12 +00:00
|
|
|
# Adding a comic to Dosage
|
2013-08-28 18:49:53 +00:00
|
|
|
|
|
|
|
To add a new comic, add a new class in one of the *.py files
|
|
|
|
in the dosagelib/plugins module.
|
|
|
|
|
2022-10-01 15:51:03 +00:00
|
|
|
The files in dosagelib/plugins and the classes inside those files are
|
2013-08-28 18:49:53 +00:00
|
|
|
sorted alphabetically. Add your comic to the appropriate filename.
|
|
|
|
For example if the comic name is "Super duper comic", the new class
|
|
|
|
should be added to dosagelib/plugins/s.py.
|
|
|
|
|
|
|
|
Here is a complete example which is explained in detail below.
|
|
|
|
|
|
|
|
```
|
|
|
|
class SuperDuperComic(_BasicScraper):
|
|
|
|
url = 'http://superdupercomic.com/'
|
|
|
|
rurl = escape(url)
|
2022-10-01 15:51:03 +00:00
|
|
|
stripUrl = url + 'comics/%s'
|
2013-08-28 18:49:53 +00:00
|
|
|
firstStripUrl = stripUrl % '1'
|
2022-10-01 15:51:03 +00:00
|
|
|
imageSearch = compile(tagre("img", "src", r'(%simg/[^"]+)' % rurl))
|
|
|
|
prevSearch = compile(tagre("a", "href", r'(%scomics/\d+)' % rurl, after="prev"))
|
2013-08-28 18:49:53 +00:00
|
|
|
help = 'Index format: n (unpadded)'
|
|
|
|
```
|
|
|
|
|
|
|
|
Let's look at each line in detail.
|
|
|
|
|
|
|
|
```class SuperDuperComic(_BasicScraper):```
|
|
|
|
|
|
|
|
All comic plugin classes inherit from ``_BasicScraper``.
|
|
|
|
The classname (``SuperDuperComic`` in our example) must be unique,
|
|
|
|
regardless of upper/lower characters.
|
|
|
|
The user finds comics with this classname, so be sure to select
|
|
|
|
something descriptive and easy to remember.
|
|
|
|
|
|
|
|
```url = 'http://superdupercomic.com/'```
|
|
|
|
|
|
|
|
The URL must display the latest comic picture. This is where the
|
|
|
|
comic image search will start. See below for some special cases.
|
|
|
|
|
|
|
|
```rurl = escape(url)```
|
|
|
|
|
|
|
|
This defines a variable ``rurl`` which is used in the search patterns
|
|
|
|
below. It properly escapes all regular expression special characters
|
|
|
|
like dots or question marks.
|
|
|
|
|
2022-10-01 15:51:03 +00:00
|
|
|
```stripUrl = url + 'comics/%s'```
|
2013-08-28 18:49:53 +00:00
|
|
|
|
|
|
|
This defines how a comic strip URL looks like. In our example, all
|
|
|
|
comic strip URLs look like ``http://superdupercomic.com/comics/NNN``
|
|
|
|
where NNN is the increasing comic number.
|
|
|
|
|
|
|
|
```firstStripUrl = stripUrl % '1'```
|
|
|
|
|
|
|
|
This tells Dosage what the earliest comic strip URL looks like. Dosage
|
2014-01-13 19:13:27 +00:00
|
|
|
stops searching for more comics when it is encounterd. In our example
|
|
|
|
comic numbering starts with ``1``, so the oldest comic URL is
|
2013-08-28 18:49:53 +00:00
|
|
|
``http://superdupercomic.com/comics/1``
|
|
|
|
|
|
|
|
```imageSearch = compile(tagre("img", "src", r'(%simg/[^"]+)' % rurl))```
|
|
|
|
|
|
|
|
Each comic page URL has one or more comic strip images. The imageSearch
|
|
|
|
pattern must match those images in the HTML content of the page URL.
|
|
|
|
To make it easy to match HTML tags, the ``tagre()`` function is
|
|
|
|
helpful. The first parameter is the tag name, the second the attribute
|
|
|
|
name and the third the attribute value. So in our example the given
|
|
|
|
pattern whould match a tag like
|
|
|
|
``<img src="http://superdupercomic.com/img/comic1.jpg" />``` .
|
|
|
|
|
2022-10-01 15:51:03 +00:00
|
|
|
```prevSearch = compile(tagre("a", "href", r'(%scomics/\d+)' % rurl, after="prev"))```
|
2013-08-28 18:49:53 +00:00
|
|
|
|
|
|
|
To search for more comics, Dosage has to look for the previous comic URL.
|
|
|
|
The ``after=`` value in ``tagre()`` matches anything between the
|
|
|
|
attribute value and the end of the tag.
|
|
|
|
So this pattern assumes each comic page URL has a link to the previous
|
2022-10-01 15:51:03 +00:00
|
|
|
comic, for example ``http://superdupercomic.com/comics/100`` has a
|
|
|
|
link ``<a href="http://superdupercomic.com/comics/99" class="prev">``.
|
2013-08-28 18:49:53 +00:00
|
|
|
|
|
|
|
``help = 'Index format: n (unpadded)'``
|
|
|
|
|
|
|
|
Since the user can search comics from a given start point, the help
|
|
|
|
must describe how the comic is numbered. Running
|
|
|
|
``dosage superdupercomic:100`` would start getting comics from number
|
|
|
|
100 and earlier.
|