[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:
Mike Fährmann
2026-01-06 09:35:47 +01:00
parent 706fb752c6
commit cf96fc6ebe
4 changed files with 89 additions and 42 deletions

View File

@@ -1,6 +1,6 @@
# -*- 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
# it under the terms of the GNU General Public License version 2 as
@@ -17,8 +17,8 @@ class KoofrSharedExtractor(Extractor):
category = "koofr"
subcategory = "shared"
root = "https://app.koofr.net"
directory_fmt = ("{category}", "{date:%Y-%m-%d} {title}")
archive_fmt = "{post[id]}_{hash|id}"
directory_fmt = ("{category}", "{post[title]} ({post[id]})", "{path:I}")
archive_fmt = "{post[id]}_{path:J/}_{hash|id}"
pattern = (r"(?:https?://)?(?:"
r"(?:app\.)?koofr\.(?:net|eu)/links/([\w-]+)|"
r"k00\.fr/(\w+))")
@@ -43,35 +43,28 @@ class KoofrSharedExtractor(Extractor):
"Sec-Fetch-Site" : "same-origin",
}
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"]
if file["type"] == "dir" and not self.config("zip", False):
path = True
url = url + "/bundle"
params["path"] = "/"
files = self.request_json(
url, params=params, headers=headers)["files"]
file["path"] = []
if file["type"] == "dir" and self.config("recursive", True):
files = self._extract_files(file, url + "/bundle", params, headers)
recursive = True
else:
path = False
files = (file,)
if password:
password = text.escape(password)
recursive = False
post = {
"id" : data["id"],
"title": data["name"],
"count": len(files),
"date" : self.parse_timestamp(file["modified"] / 1000),
}
yield Message.Directory, "", post
for num, file in enumerate(files, 1):
file["count"] = len(files)
file["num"] = num
base = (f"{data.get('publicUrlBase') or self.root}"
f"/content/links/{uuid}/files/get/")
headers = {"Referer": referer}
password = "&password=" + text.escape(password) if password else ""
for file in files:
file["post"] = post
file["date"] = self.parse_timestamp(file["modified"] / 1000)
file["_http_headers"] = headers
@@ -79,9 +72,34 @@ class KoofrSharedExtractor(Extractor):
name = file["name"]
text.nameext_from_name(name, file)
name = text.escape(name)
url = (f"{base}{name}?path=%2F{name if path else '&force'}")
if password:
url = f"{url}&password={password}"
if recursive:
if path := file["path"]:
path = f"{'/'.join(path)}/{name}"
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
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