| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
"""Extractors for https://pictoa.com/""" |
| 8 |
|
| 9 |
from .common import Extractor, Message |
| 10 |
from .. import text |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?(?:[\w]+\.)?pictoa\.com(?:\.de)?" |
| 13 |
|
| 14 |
|
| 15 |
class PictoaExtractor(Extractor): |
| 16 |
"""Base class for pictoa extractors""" |
| 17 |
category = "pictoa" |
| 18 |
root = "https://pictoa.com" |
| 19 |
directory_fmt = ("{category}", "{album_id} {album_title}") |
| 20 |
filename_fmt = "{id}.{extension}" |
| 21 |
archive_fmt = "{id}" |
| 22 |
|
| 23 |
|
| 24 |
class PictoaImageExtractor(PictoaExtractor): |
| 25 |
"""Extractor for single images from pictoa.com""" |
| 26 |
subcategory = "image" |
| 27 |
pattern = BASE_PATTERN + r"/albums/(?:[\w-]+-)?(\d+)/(\d+)" |
| 28 |
example = "https://www.pictoa.com/albums/NAME-12345/12345.html" |
| 29 |
|
| 30 |
def items(self): |
| 31 |
album_id, image_id = self.groups |
| 32 |
|
| 33 |
url = f"{self.root}/albums/{album_id}/{image_id}.html" |
| 34 |
page = self.request(url).text |
| 35 |
album_title = text.extr(page, 'property="og:title" content="', '"') |
| 36 |
image_url = text.extr(page, 'property="og:image" content="', '"') |
| 37 |
|
| 38 |
data = { |
| 39 |
"album_id" : album_id, |
| 40 |
"album_title": album_title.rpartition(" #")[0], |
| 41 |
"id" : image_id, |
| 42 |
"url" : image_url, |
| 43 |
} |
| 44 |
|
| 45 |
text.nameext_from_url(image_url, data) |
| 46 |
yield Message.Directory, "", data |
| 47 |
yield Message.Url, image_url, data |
| 48 |
|
| 49 |
|
| 50 |
class PictoaAlbumExtractor(PictoaExtractor): |
| 51 |
"""Extractor for image albums from pictoa.com""" |
| 52 |
subcategory = "album" |
| 53 |
pattern = BASE_PATTERN + r"/albums/(?:[\w-]+-)?(\d+).html" |
| 54 |
example = "https://www.pictoa.com/albums/NAME-12345.html" |
| 55 |
|
| 56 |
def items(self): |
| 57 |
album_id = self.groups[0] |
| 58 |
url = f"{self.root}/albums/{album_id}.html" |
| 59 |
page = self.request(url).text |
| 60 |
|
| 61 |
album_data = { |
| 62 |
"album_id" : album_id, |
| 63 |
"album_title": text.extr(page, "<h1>", "<"), |
| 64 |
"tags" : text.split_html(text.extr( |
| 65 |
page, '<ol class="related-categories', '</ol>'))[1:], |
| 66 |
"_extractor" : PictoaImageExtractor, |
| 67 |
} |
| 68 |
|
| 69 |
while True: |
| 70 |
container = text.extr(page, '<main>', '<span id="flag" >') |
| 71 |
for url in text.extract_iter( |
| 72 |
container, '<a rel="nofollow" href="', '"'): |
| 73 |
yield Message.Queue, url, album_data |
| 74 |
|
| 75 |
url = text.extr(page, '<link rel="next" href="', '"') |
| 76 |
if not url: |
| 77 |
break |
| 78 |
page = self.request(url).text |