aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/bunkr.py
blob: 882c2b3dc48f144f8f7654cc7e750f0d7da29679 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-

# Copyright 2022 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://bunkr.ru/"""

from .lolisafe import LolisafeAlbumExtractor
from .. import text
import json


class BunkrAlbumExtractor(LolisafeAlbumExtractor):
    """Extractor for bunkr.ru albums"""
    category = "bunkr"
    root = "https://bunkr.ru"
    pattern = r"(?:https?://)?(?:app\.)?bunkr\.(?:ru|is|to)/a/([^/?#]+)"
    test = (
        ("https://bunkr.ru/a/Lktg9Keq", {
            "pattern": r"https://cdn\.bunkr\.ru/test-テスト-\"&>-QjgneIQv\.png",
            "content": "0c8768055e4e20e7c7259608b67799171b691140",
            "keyword": {
                "album_id": "Lktg9Keq",
                "album_name": 'test テスト "&>',
                "count": 1,
                "filename": 'test-テスト-"&>-QjgneIQv',
                "id": "QjgneIQv",
                "name": 'test-テスト-"&>',
                "num": int,
            },
        }),
        # mp4 (#2239)
        ("https://app.bunkr.is/a/ptRHaCn2", {
            "pattern": r"https://media-files\.bunkr\.ru/_-RnHoW69L\.mp4",
            "content": "80e61d1dbc5896ae7ef9a28734c747b28b320471",
        }),
        # cdn4
        ("https://bunkr.is/a/iXTTc1o2", {
            "pattern": r"https://(cdn|media-files)4\.bunkr\.ru/",
            "content": "da29aae371b7adc8c5ef8e6991b66b69823791e8",
        }),
        ("https://bunkr.to/a/Lktg9Keq"),
    )

    def fetch_album(self, album_id):
        root = self.root

        try:
            data = json.loads(text.extr(
                self.request(root + "/a/" + self.album_id).text,
                'id="__NEXT_DATA__" type="application/json">', '<'))
            album = data["props"]["pageProps"]["album"]
            files = album["files"]
        except Exception as exc:
            self.log.debug("%s: %s", exc.__class__.__name__, exc)
            self.root = root.replace("://", "://app.", 1)
            files, data = LolisafeAlbumExtractor.fetch_album(self, album_id)
        else:
            for file in files:
                file["file"] = file["cdn"] + "/" + file["name"]
            data = {
                "album_id"   : self.album_id,
                "album_name" : text.unescape(album["name"]),
                "description": text.unescape(album["description"]),
                "count"      : len(files),
            }

        headers = {"Referer": root.replace("://", "://stream.", 1) + "/"}
        for file in files:
            if file["file"].endswith(
                    (".mp4", ".m4v", ".mov", ".webm", ".zip", ".rar", ".7z")):
                file["_http_headers"] = headers
                file["file"] = file["file"].replace(
                    "://cdn", "://media-files", 1)

        return files, data