[koofr] refactor (#8803)
https://github.com/mikf/gallery-dl/issues/8803#issuecomment-3708215475 https://github.com/mikf/gallery-dl/issues/8803#issuecomment-3708358606 - add 'recursive' option, remove 'zip' - recurse into subdirectories - add 'path' metadata - remove 'count' & 'num' metadata - update default directory & archive format
This commit is contained in:
@@ -4073,14 +4073,18 @@ Description
|
|||||||
the first in the list gets chosen (usually `mp3`).
|
the first in the list gets chosen (usually `mp3`).
|
||||||
|
|
||||||
|
|
||||||
extractor.koofr.zip
|
extractor.koofr.recursive
|
||||||
-------------------
|
-------------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
``bool``
|
||||||
Default
|
Default
|
||||||
``false``
|
``true``
|
||||||
Description
|
Description
|
||||||
Download shared `/links/` with multiple files as a single `.zip` file.
|
``true``
|
||||||
|
Recursively descent into subfolders
|
||||||
|
while downloading individual files.
|
||||||
|
``false``
|
||||||
|
Download shared `/links/` with multiple files as a single `.zip` file.
|
||||||
|
|
||||||
|
|
||||||
extractor.lolisafe.domain
|
extractor.lolisafe.domain
|
||||||
|
|||||||
@@ -520,7 +520,7 @@
|
|||||||
},
|
},
|
||||||
"koofr":
|
"koofr":
|
||||||
{
|
{
|
||||||
"zip": false
|
"recursive": true
|
||||||
},
|
},
|
||||||
"luscious":
|
"luscious":
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2025 Mike Fährmann
|
# Copyright 2025-2026 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -17,8 +17,8 @@ class KoofrSharedExtractor(Extractor):
|
|||||||
category = "koofr"
|
category = "koofr"
|
||||||
subcategory = "shared"
|
subcategory = "shared"
|
||||||
root = "https://app.koofr.net"
|
root = "https://app.koofr.net"
|
||||||
directory_fmt = ("{category}", "{date:%Y-%m-%d} {title}")
|
directory_fmt = ("{category}", "{post[title]} ({post[id]})", "{path:I}")
|
||||||
archive_fmt = "{post[id]}_{hash|id}"
|
archive_fmt = "{post[id]}_{path:J/}_{hash|id}"
|
||||||
pattern = (r"(?:https?://)?(?:"
|
pattern = (r"(?:https?://)?(?:"
|
||||||
r"(?:app\.)?koofr\.(?:net|eu)/links/([\w-]+)|"
|
r"(?:app\.)?koofr\.(?:net|eu)/links/([\w-]+)|"
|
||||||
r"k00\.fr/(\w+))")
|
r"k00\.fr/(\w+))")
|
||||||
@@ -43,35 +43,28 @@ class KoofrSharedExtractor(Extractor):
|
|||||||
"Sec-Fetch-Site" : "same-origin",
|
"Sec-Fetch-Site" : "same-origin",
|
||||||
}
|
}
|
||||||
data = self.request_json(url, params=params, headers=headers)
|
data = self.request_json(url, params=params, headers=headers)
|
||||||
root = data.get("publicUrlBase") or self.root
|
|
||||||
base = f"{root}/content/links/{uuid}/files/get/"
|
|
||||||
headers = {"Referer": referer}
|
|
||||||
file = data["file"]
|
file = data["file"]
|
||||||
|
file["path"] = []
|
||||||
if file["type"] == "dir" and not self.config("zip", False):
|
if file["type"] == "dir" and self.config("recursive", True):
|
||||||
path = True
|
files = self._extract_files(file, url + "/bundle", params, headers)
|
||||||
url = url + "/bundle"
|
recursive = True
|
||||||
params["path"] = "/"
|
|
||||||
files = self.request_json(
|
|
||||||
url, params=params, headers=headers)["files"]
|
|
||||||
else:
|
else:
|
||||||
path = False
|
|
||||||
files = (file,)
|
files = (file,)
|
||||||
|
recursive = False
|
||||||
if password:
|
|
||||||
password = text.escape(password)
|
|
||||||
|
|
||||||
post = {
|
post = {
|
||||||
"id" : data["id"],
|
"id" : data["id"],
|
||||||
"title": data["name"],
|
"title": data["name"],
|
||||||
"count": len(files),
|
|
||||||
"date" : self.parse_timestamp(file["modified"] / 1000),
|
"date" : self.parse_timestamp(file["modified"] / 1000),
|
||||||
}
|
}
|
||||||
|
|
||||||
yield Message.Directory, "", post
|
base = (f"{data.get('publicUrlBase') or self.root}"
|
||||||
for num, file in enumerate(files, 1):
|
f"/content/links/{uuid}/files/get/")
|
||||||
file["count"] = len(files)
|
headers = {"Referer": referer}
|
||||||
file["num"] = num
|
password = "&password=" + text.escape(password) if password else ""
|
||||||
|
|
||||||
|
for file in files:
|
||||||
file["post"] = post
|
file["post"] = post
|
||||||
file["date"] = self.parse_timestamp(file["modified"] / 1000)
|
file["date"] = self.parse_timestamp(file["modified"] / 1000)
|
||||||
file["_http_headers"] = headers
|
file["_http_headers"] = headers
|
||||||
@@ -79,9 +72,34 @@ class KoofrSharedExtractor(Extractor):
|
|||||||
name = file["name"]
|
name = file["name"]
|
||||||
text.nameext_from_name(name, file)
|
text.nameext_from_name(name, file)
|
||||||
|
|
||||||
name = text.escape(name)
|
if recursive:
|
||||||
url = (f"{base}{name}?path=%2F{name if path else '&force'}")
|
if path := file["path"]:
|
||||||
if password:
|
path = f"{'/'.join(path)}/{name}"
|
||||||
url = f"{url}&password={password}"
|
else:
|
||||||
|
path = name
|
||||||
|
else:
|
||||||
|
path = ""
|
||||||
|
password += "&force"
|
||||||
|
|
||||||
|
url = (f"{base}{text.escape(name)}"
|
||||||
|
f"?path=/{text.escape(path)}{password}")
|
||||||
|
|
||||||
|
yield Message.Directory, "", file
|
||||||
yield Message.Url, url, file
|
yield Message.Url, url, file
|
||||||
|
|
||||||
|
def _extract_files(self, dir, url, params, headers):
|
||||||
|
path = dir["path"]
|
||||||
|
params["path"] = "/" + "/".join(path)
|
||||||
|
|
||||||
|
files = self.request_json(
|
||||||
|
url, params=params, headers=headers)["files"]
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
if file["type"] == "dir":
|
||||||
|
file["path"] = path.copy()
|
||||||
|
file["path"].append(file["name"])
|
||||||
|
yield from self._extract_files(
|
||||||
|
file, url, params.copy(), headers)
|
||||||
|
else:
|
||||||
|
file["path"] = path
|
||||||
|
yield file
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ __tests__ = (
|
|||||||
{
|
{
|
||||||
"#url" : "https://k00.fr/cltf71jr",
|
"#url" : "https://k00.fr/cltf71jr",
|
||||||
"#class" : koofr.KoofrSharedExtractor,
|
"#class" : koofr.KoofrSharedExtractor,
|
||||||
"#results" : "https://app.koofr.net/content/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0/files/get/wsf-form-job-application-form.json?path=%2F&force",
|
"#results" : "https://app.koofr.net/content/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0/files/get/wsf-form-job-application-form.json?path=/&force",
|
||||||
"#sha1_content": "f65ccc63a99165ecb9ff2ab92302c25b245a904f",
|
"#sha1_content": "f65ccc63a99165ecb9ff2ab92302c25b245a904f",
|
||||||
|
|
||||||
"contentType": "application/json",
|
"contentType": "application/json",
|
||||||
@@ -28,7 +28,7 @@ __tests__ = (
|
|||||||
{
|
{
|
||||||
"#url" : "https://app.koofr.net/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0",
|
"#url" : "https://app.koofr.net/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0",
|
||||||
"#class" : koofr.KoofrSharedExtractor,
|
"#class" : koofr.KoofrSharedExtractor,
|
||||||
"#results" : "https://app.koofr.net/content/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0/files/get/wsf-form-job-application-form.json?path=%2F&force",
|
"#results" : "https://app.koofr.net/content/links/923b4f56-3aaf-49ee-95e3-d85c52b687b0/files/get/wsf-form-job-application-form.json?path=/&force",
|
||||||
"#sha1_content": "f65ccc63a99165ecb9ff2ab92302c25b245a904f",
|
"#sha1_content": "f65ccc63a99165ecb9ff2ab92302c25b245a904f",
|
||||||
|
|
||||||
"contentType": "application/json",
|
"contentType": "application/json",
|
||||||
@@ -52,12 +52,12 @@ __tests__ = (
|
|||||||
"#comment" : "individual files",
|
"#comment" : "individual files",
|
||||||
"#class" : koofr.KoofrSharedExtractor,
|
"#class" : koofr.KoofrSharedExtractor,
|
||||||
"#options" : {"zip": False},
|
"#options" : {"zip": False},
|
||||||
"#pattern" : r"https://app\.koofr\.net/content/links/01deac62\-f5d6\-4d2b\-7043\-53b24cc0a038/files/get/smw_msu1\-\d+\.pcm\?path=%2Fsmw_msu1\-\d+\.pcm",
|
"#pattern" : r"https://app\.koofr\.net/content/links/01deac62\-f5d6\-4d2b\-7043\-53b24cc0a038/files/get/smw_msu1\-\d+\.pcm\?path=/smw_msu1\-\d+\.pcm",
|
||||||
"#count" : 18,
|
"#count" : 18,
|
||||||
|
|
||||||
"contentType": "application/octet-stream",
|
"contentType": "application/octet-stream",
|
||||||
"count" : 18,
|
"!count" : 18,
|
||||||
"num" : range(1, 18),
|
"!num" : range(1, 18),
|
||||||
"date" : "type:datetime",
|
"date" : "type:datetime",
|
||||||
"extension" : "pcm",
|
"extension" : "pcm",
|
||||||
"filename" : r"re:smw_msu1-\d+",
|
"filename" : r"re:smw_msu1-\d+",
|
||||||
@@ -68,7 +68,7 @@ __tests__ = (
|
|||||||
"tags" : {},
|
"tags" : {},
|
||||||
"type" : "file",
|
"type" : "file",
|
||||||
"post" : {
|
"post" : {
|
||||||
"count" : 18,
|
"!count" : 18,
|
||||||
"date" : "dt:2023-11-19 16:27:56",
|
"date" : "dt:2023-11-19 16:27:56",
|
||||||
"id" : "01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
"id" : "01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
||||||
"title" : "Church of Kondo",
|
"title" : "Church of Kondo",
|
||||||
@@ -79,26 +79,51 @@ __tests__ = (
|
|||||||
"#url" : "https://app.koofr.net/links/01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
"#url" : "https://app.koofr.net/links/01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
||||||
"#comment" : ".zip container",
|
"#comment" : ".zip container",
|
||||||
"#class" : koofr.KoofrSharedExtractor,
|
"#class" : koofr.KoofrSharedExtractor,
|
||||||
"#options" : {"zip": True},
|
"#options" : {"recursive": False},
|
||||||
"#results" : "https://app.koofr.net/content/links/01deac62-f5d6-4d2b-7043-53b24cc0a038/files/get/Church of Kondo?path=%2F&force",
|
"#results" : "https://app.koofr.net/content/links/01deac62-f5d6-4d2b-7043-53b24cc0a038/files/get/Church of Kondo?path=/&force",
|
||||||
|
|
||||||
"contentType": "",
|
"contentType": "",
|
||||||
"count" : 1,
|
"!count" : 1,
|
||||||
|
"!num" : 1,
|
||||||
"date" : "dt:2023-11-19 16:27:56",
|
"date" : "dt:2023-11-19 16:27:56",
|
||||||
"extension" : "",
|
"extension" : "",
|
||||||
"filename" : "Church of Kondo",
|
"filename" : "Church of Kondo",
|
||||||
"modified" : 1700411276087,
|
"modified" : 1700411276087,
|
||||||
"name" : "Church of Kondo",
|
"name" : "Church of Kondo",
|
||||||
"num" : 1,
|
|
||||||
"size" : 0,
|
"size" : 0,
|
||||||
"tags" : {},
|
"tags" : {},
|
||||||
"type" : "dir",
|
"type" : "dir",
|
||||||
"post" : {
|
"post" : {
|
||||||
"count" : 1,
|
"!count" : 1,
|
||||||
"date" : "dt:2023-11-19 16:27:56",
|
"date" : "dt:2023-11-19 16:27:56",
|
||||||
"id" : "01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
"id" : "01deac62-f5d6-4d2b-7043-53b24cc0a038",
|
||||||
"title" : "Church of Kondo",
|
"title" : "Church of Kondo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"#url" : "https://app.koofr.net/links/7667d857-c639-4f38-93d1-c42394492a0c",
|
||||||
|
"#comment" : "recursive directories",
|
||||||
|
"#class" : koofr.KoofrSharedExtractor,
|
||||||
|
"#pattern" : r"https://app\.koofr\.net/content/links/7667d857\-c639\-4f38\-93d1\-c42394492a0c/files/get/[\w]\.png\?path=/.*\w\.png",
|
||||||
|
"#count" : 16,
|
||||||
|
|
||||||
|
"contentType": "image/png",
|
||||||
|
"date" : "type:datetime",
|
||||||
|
"extension" : "png",
|
||||||
|
"filename" : r"re:^[1-8a-d]$",
|
||||||
|
"hash" : "hash:md5",
|
||||||
|
"modified" : range(1767688000000, 1767700000000),
|
||||||
|
"name" : r"re:^[1-8a-d]\.png",
|
||||||
|
"path" : {(), ("dir-l1-1",), ("dir-l1-2",), ("dir-l1-1", "dir-l2-1")},
|
||||||
|
"size" : range(200, 999),
|
||||||
|
"tags" : {},
|
||||||
|
"type" : "file",
|
||||||
|
"post" : {
|
||||||
|
"date" : "dt:2026-01-06 08:27:26",
|
||||||
|
"id" : "7667d857-c639-4f38-93d1-c42394492a0c",
|
||||||
|
"title": "dir",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user