Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/gallery_dl/extractor/catbox.py
5399 views
1
# -*- coding: utf-8 -*-
2
3
# Copyright 2022-2023 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://catbox.moe/"""
10
11
from .common import GalleryExtractor, Extractor, Message
12
from .. import text
13
14
15
class CatboxAlbumExtractor(GalleryExtractor):
16
"""Extractor for catbox albums"""
17
category = "catbox"
18
subcategory = "album"
19
root = "https://catbox.moe"
20
filename_fmt = "{filename}.{extension}"
21
directory_fmt = ("{category}", "{album_name} ({album_id})")
22
archive_fmt = "{album_id}_{filename}"
23
pattern = r"(?:https?://)?(?:www\.)?catbox\.moe(/c/[^/?#]+)"
24
example = "https://catbox.moe/c/ID"
25
26
def metadata(self, page):
27
extr = text.extract_from(page)
28
return {
29
"album_id" : self.page_url.rpartition("/")[2],
30
"album_name" : text.unescape(extr("<h1>", "<")),
31
"date" : text.parse_datetime(extr(
32
"<p>Created ", "<"), "%B %d %Y"),
33
"description": text.unescape(extr("<p>", "<")),
34
}
35
36
def images(self, page):
37
return [
38
("https://files.catbox.moe/" + path, None)
39
for path in text.extract_iter(
40
page, ">https://files.catbox.moe/", "<")
41
]
42
43
44
class CatboxFileExtractor(Extractor):
45
"""Extractor for catbox files"""
46
category = "catbox"
47
subcategory = "file"
48
archive_fmt = "{filename}"
49
pattern = r"(?:https?://)?(?:files|litter|de)\.catbox\.moe/([^/?#]+)"
50
example = "https://files.catbox.moe/NAME.EXT"
51
52
def items(self):
53
url = text.ensure_http_scheme(self.url)
54
file = text.nameext_from_url(url, {"url": url})
55
yield Message.Directory, file
56
yield Message.Url, url, file
57
58