summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/lolisafe.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-12-30 01:56:41 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-12-30 01:56:41 -0500
commit7bc30b43b70556630b4a93c03fefc0d888e3d19f (patch)
treefb0e96762ab8137d23f248ef303538d8d6ff4368 /gallery_dl/extractor/lolisafe.py
parenta5aecc343fd2886e7ae09bb3e2afeec38f175755 (diff)
New upstream version 1.20.0.upstream/1.20.0
Diffstat (limited to 'gallery_dl/extractor/lolisafe.py')
-rw-r--r--gallery_dl/extractor/lolisafe.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/gallery_dl/extractor/lolisafe.py b/gallery_dl/extractor/lolisafe.py
new file mode 100644
index 0000000..cdaf22b
--- /dev/null
+++ b/gallery_dl/extractor/lolisafe.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2021 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 lolisafe/chibisafe instances"""
+
+from .common import BaseExtractor, Message
+from .. import text
+
+
+class LolisafeExtractor(BaseExtractor):
+ """Base class for lolisafe extractors"""
+ basecategory = "lolisafe"
+ directory_fmt = ("{category}", "{album_name} ({album_id})")
+ archive_fmt = "{album_id}_{id}"
+
+
+BASE_PATTERN = LolisafeExtractor.update({
+ "bunkr": {"root": "https://bunkr.is", "pattern": r"bunkr\.(?:is|to)"},
+ "zzzz" : {"root": "https://zz.ht" , "pattern": r"zz\.(?:ht|fo)"},
+})
+
+
+class LolisafelbumExtractor(LolisafeExtractor):
+ subcategory = "album"
+ pattern = BASE_PATTERN + "/a/([^/?#]+)"
+ test = (
+ ("https://bunkr.is/a/Lktg9Keq", {
+ "pattern": r"https://cdn\.bunkr\.is/test-テスト-\"&>-QjgneIQv\.png",
+ "content": "0c8768055e4e20e7c7259608b67799171b691140",
+ "keyword": {
+ "album_id": "Lktg9Keq",
+ "album_name": 'test テスト "&>',
+ "count": 1,
+ "filename": 'test-テスト-"&>-QjgneIQv',
+ "id": "QjgneIQv",
+ "name": 'test-テスト-"&>',
+ "num": int,
+ },
+ }),
+ ("https://bunkr.to/a/Lktg9Keq"),
+ ("https://zz.ht/a/lop7W6EZ", {
+ "pattern": r"https://z\.zz\.fo/(4anuY|ih560)\.png",
+ "count": 2,
+ "keyword": {
+ "album_id": "lop7W6EZ",
+ "album_name": "ferris",
+ },
+ }),
+ ("https://zz.fo/a/lop7W6EZ"),
+ )
+
+ def __init__(self, match):
+ LolisafeExtractor.__init__(self, match)
+ self.album_id = match.group(match.lastindex)
+
+ def items(self):
+ files, data = self.fetch_album(self.album_id)
+
+ yield Message.Directory, data
+ for data["num"], file in enumerate(files, 1):
+ url = file["file"]
+ text.nameext_from_url(url, data)
+ data["name"], sep, data["id"] = data["filename"].rpartition("-")
+ yield Message.Url, url, data
+
+ def fetch_album(self, album_id):
+ url = "{}/api/album/get/{}".format(self.root, album_id)
+ data = self.request(url).json()
+
+ return data["files"], {
+ "album_id" : self.album_id,
+ "album_name": text.unescape(data["title"]),
+ "count" : data["count"],
+ }