Debian Codegraph @

gallery_dl/extractor/kabeuchi.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2020-2025 Mike Fährmann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 """Extractors for https://kabe-uchiroom.com/"""
10
11 from .common import Extractor, Message
12 from .. import text
13
14
15 class KabeuchiUserExtractor(Extractor):
16 """Extractor for all posts of a user on kabe-uchiroom.com"""
17 category = "kabeuchi"
18 subcategory = "user"
19 directory_fmt = ("{category}", "{twitter_user_id} {twitter_id}")
20 filename_fmt = "{id}_{num:>02}{title:?_//}.{extension}"
21 archive_fmt = "{id}_{num}"
22 root = "https://kabe-uchiroom.com"
23 pattern = r"(?:https?://)?kabe-uchiroom\.com/mypage/?\?id=(\d+)"
24 example = "https://kabe-uchiroom.com/mypage/?id=12345"
25
26 def items(self):
27 uid = self.groups[0]
28 base = f"{self.root}/accounts/upfile/{uid[-1]}/{uid}/"
29 keys = ("image1", "image2", "image3", "image4", "image5", "image6")
30
31 for post in self.posts(uid):
32 if post.get("is_ad") or not post["image1"]:
33 continue
34
35 post["date"] = self.parse_datetime_iso(post["created_at"])
36 yield Message.Directory, "", post
37
38 for key in keys:
39 name = post[key]
40 if not name:
41 break
42 url = base + name
43 post["num"] = ord(key[-1]) - 48
44 yield Message.Url, url, text.nameext_from_url(name, post)
45
46 def posts(self, uid):
47 url = f"{self.root}/mypage/?id={uid}"
48 response = self.request(url)
49 if response.history and response.url == self.root + "/":
50 raise self.exc.NotFoundError("user")
51 target_id = text.extr(response.text, 'user_friend_id = "', '"')
52 return self._pagination(target_id)
53
54 def _pagination(self, target_id):
55 url = self.root + "/get_posts.php"
56 data = {
57 "user_id" : "0",
58 "target_id" : target_id,
59 "type" : "uploads",
60 "sort_type" : "0",
61 "category_id": "all",
62 "latest_post": "",
63 "page_num" : 0,
64 }
65
66 while True:
67 info = self.request_json(url, method="POST", data=data)
68 datas = info["datas"]
69
70 if not datas or not isinstance(datas, list):
71 return
72 yield from datas
73
74 last_id = datas[-1]["id"]
75 if last_id == info["last_data"]:
76 return
77 data["latest_post"] = last_id
78 data["page_num"] += 1