1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 03:32:33 +01:00
gallery-dl/gallery_dl/extractor/cyberdrop.py
Mike Fährmann f33c2ef73b
[cyberdrop] extract direct download URLs (#1943)
do not rely on redirects from f.cyberdrop.cc
2021-10-10 23:05:29 +02:00

63 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
# 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://cyberdrop.me/"""
from .common import Extractor, Message
from .. import text
class CyberdropAlbumExtractor(Extractor):
category = "cyberdrop"
subcategory = "album"
root = "https://cyberdrop.me"
directory_fmt = ("{category}", "{album_name} ({album_id})")
archive_fmt = "{album_id}_{id}"
pattern = r"(?:https?://)?(?:www\.)?cyberdrop\.me/a/([^/?#]+)"
test = ("https://cyberdrop.me/a/keKRjm4t", {
"pattern": r"https://fs-\d+\.cyberdrop\.to/.*\.[a-z]+$",
"keyword": {
"album_id": "keKRjm4t",
"album_name": "Fate (SFW)",
"album_size": 150069254,
"count": 62,
"date": "dt:2020-06-18 13:14:20",
"description": "",
"id": r"re:\w{8}",
},
})
def __init__(self, match):
Extractor.__init__(self, match)
self.album_id = match.group(1)
def items(self):
url = self.root + "/a/" + self.album_id
extr = text.extract_from(self.request(url).text)
files = []
append = files.append
while True:
url = extr('downloadUrl: "', '"')
if not url:
break
append(text.unescape(url))
data = {
"album_id" : self.album_id,
"album_name" : extr("name: '", "'"),
"date" : text.parse_timestamp(extr("timestamp: ", ",")),
"album_size" : text.parse_int(extr("totalSize: ", ",")),
"description": extr("description: `", "`"),
"count" : len(files),
}
yield Message.Directory, data
for url in files:
text.nameext_from_url(url, data)
data["filename"], _, data["id"] = data["filename"].rpartition("-")
yield Message.Url, url, data