aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/comedywildlifephoto.py
blob: a1c1ef456d5ba184b287896015d016f6e57328ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-

# Copyright 2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extractors for https://www.comedywildlifephoto.com/"""

from .common import GalleryExtractor
from .. import text


class ComedywildlifephotoGalleryExtractor(GalleryExtractor):
    """Extractor for comedywildlifephoto galleries"""
    category = "comedywildlifephoto"
    root = "https://www.comedywildlifephoto.com"
    directory_fmt = ("{category}", "{section}", "{title}")
    filename_fmt = "{num:>03} {filename}.{extension}"
    archive_fmt = "{section}/{title}/{num}"
    pattern = (r"(?:https?://)?(?:www\.)?comedywildlifephoto\.com"
               r"(/gallery/[^/?#]+/[^/?#]+\.php)")
    example = "https://www.comedywildlifephoto.com/gallery/SECTION/TITLE.php"

    def metadata(self, page):
        extr = text.extract_from(page)

        return {
            "section": extr("<h1>", "<").strip(),
            "title"  : extr(">", "<"),
            "description": text.unescape(extr(
                'class="c1 np">', "<div")),
        }

    def images(self, page):
        results = []

        for fig in text.extract_iter(page, "<figure", "</figure>"):
            width, _, height = text.extr(
                fig, 'data-size="', '"').partition("x")
            results.append((
                self.root + text.extr(fig, 'href="', '"'), {
                    "width"  : text.parse_int(width),
                    "height" : text.parse_int(height),
                    "caption": text.unescape(text.extr(
                        fig, "<figcaption>", "<")),
                }
            ))

        return results