[koofr] improve subdirectory handling - re-add 'num' & 'count'

This commit is contained in:
Mike Fährmann
2026-02-12 21:37:18 +01:00
parent 866e6df7a8
commit 34e402a01d
2 changed files with 48 additions and 34 deletions

View File

@@ -18,7 +18,7 @@ class KoofrSharedExtractor(Extractor):
subcategory = "shared" subcategory = "shared"
root = "https://app.koofr.net" root = "https://app.koofr.net"
directory_fmt = ("{category}", "{post[title]} ({post[id]})", "{path:I}") directory_fmt = ("{category}", "{post[title]} ({post[id]})", "{path:I}")
filename_fmt = "{filename} ({hash[:8]}).{extension}" filename_fmt = "{num:>03} {filename} ({hash|id:[:8]}).{extension}"
archive_fmt = "{post[id]}_{path:J/}_{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-]+)|"
@@ -48,10 +48,10 @@ class KoofrSharedExtractor(Extractor):
file = data["file"] file = data["file"]
file["path"] = [] file["path"] = []
if file["type"] == "dir" and self.config("recursive", True): if file["type"] == "dir" and self.config("recursive", True):
files = self._extract_files(file, url + "/bundle", params, headers) items = self._extract_files(file, url + "/bundle", params, headers)
recursive = True recursive = True
else: else:
files = (file,) items = ((file, (file,)),)
recursive = False recursive = False
post = { post = {
@@ -65,42 +65,54 @@ class KoofrSharedExtractor(Extractor):
headers = {"Referer": referer} headers = {"Referer": referer}
password = "&password=" + text.escape(password) if password else "" password = "&password=" + text.escape(password) if password else ""
for file in files: for dir, files in items:
file["post"] = post dir["post"] = post
file["date"] = self.parse_timestamp(file["modified"] / 1000) dir["count"] = count = len(files)
file["_http_headers"] = headers yield Message.Directory, "", dir
name = file["name"] num = 0
text.nameext_from_name(name, file) for file in files:
num += 1
file["num"] = num
file["count"] = count
file["post"] = post
file["date"] = self.parse_timestamp(file["modified"] / 1000)
file["_http_headers"] = headers
if recursive: name = file["name"]
if path := file["path"]: text.nameext_from_name(name, file)
path = f"{'/'.join(path)}/{name}"
if recursive:
if path := file["path"]:
path = f"{'/'.join(path)}/{name}"
else:
path = name
else: else:
path = name path = ""
else: password += "&force"
path = ""
password += "&force"
url = (f"{base}{text.escape(name)}" url = (f"{base}{text.escape(name)}"
f"?path=/{text.escape(path)}{password}") f"?path=/{text.escape(path)}{password}")
yield Message.Url, url, file
yield Message.Directory, "", file
yield Message.Url, url, file
def _extract_files(self, dir, url, params, headers): def _extract_files(self, dir, url, params, headers):
path = dir["path"] path = dir["path"]
params["path"] = "/" + "/".join(path) params["path"] = "/" + "/".join(path)
files = self.request_json( items = self.request_json(
url, params=params, headers=headers)["files"] url, params=params, headers=headers)["files"]
for file in files: dirs = []
if file["type"] == "dir": files = []
file["path"] = path.copy() for item in items:
file["path"].append(file["name"]) if item["type"] == "dir":
yield from self._extract_files( item["path"] = path.copy()
file, url, params.copy(), headers) item["path"].append(item["name"])
dirs.append(item)
else: else:
file["path"] = path item["path"] = path
yield file files.append(item)
yield dir, files
for sub in dirs:
yield from self._extract_files(sub, url, params.copy(), headers)

View File

@@ -56,8 +56,8 @@ __tests__ = (
"#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+",
@@ -83,8 +83,8 @@ __tests__ = (
"#results" : "https://app.koofr.net/content/links/01deac62-f5d6-4d2b-7043-53b24cc0a038/files/get/Church of Kondo?path=/&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, "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",
@@ -109,6 +109,8 @@ __tests__ = (
"#count" : 16, "#count" : 16,
"contentType": "image/png", "contentType": "image/png",
"count" : 4,
"num" : range(1, 4),
"date" : "type:datetime", "date" : "type:datetime",
"extension" : "png", "extension" : "png",
"filename" : r"re:^[1-8a-d]$", "filename" : r"re:^[1-8a-d]$",