From 9068ec6a8ebbbc7f49d0a9819745f97ee3fdc9e8 Mon Sep 17 00:00:00 2001 From: Danila Kamaev Date: Mon, 25 May 2026 15:27:01 +0400 Subject: [PATCH] improve opds compatibility (#1463) use absolute paths and generate IDs --- copyparty/httpcli.py | 26 ++++++++++++++++++-------- copyparty/web/opds.xml | 4 ++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 682721ec..91a5803b 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -7187,18 +7187,19 @@ class HttpCli(object): dirs = [] files = [] ptn_hr = RE_HR - use_abs_url = ( - not is_opds - and not is_ls - and not is_js - and not self.trailing_slash - and vpath + use_abs_url = is_opds or ( + vpath and not is_ls and not is_js and not self.trailing_slash ) for fn in ls_names: base = "" href = fn if use_abs_url: - base = "/" + vpath + "/" + if is_opds: + base = self.args.SRS + if vpath: + base += vpath + "/" + else: + base = "/" + vpath + "/" href = base + fn if fn in vfs_virt: @@ -7528,17 +7529,26 @@ class HttpCli(object): ] j2a["opds_osd"] = "%s%s?opds&osd" % (self.args.SRS, quotep(vpath)) - + j2a["opds_id"] = uuid.uuid5(uuid.NAMESPACE_URL, vpath + "/").urn + j2a["opds_title"] = ( + (vpath.rsplit("/", 1)[-1] + "/") if vpath else self.args.bname + ) for item in dirs: href = item["href"] href += ("&" if "?" in href else "?") + "opds" item["href"] = href + item["opds_id"] = uuid.uuid5( + uuid.NAMESPACE_URL, "%s/%s" % (vpath, item["name"]) + ).urn item["iso8601"] = "%sZ" % (item["dt"].replace(" ", "T"),) for item in files: href = item["href"] href += ("&" if "?" in href else "?") + "dl" item["href"] = href + item["opds_id"] = uuid.uuid5( + uuid.NAMESPACE_URL, "%s/%s" % (vpath, item["name"]) + ).urn item["iso8601"] = "%sZ" % (item["dt"].replace(" ", "T"),) if "rmagic" in self.vn.flags: diff --git a/copyparty/web/opds.xml b/copyparty/web/opds.xml index ea89edf7..d3c52d1a 100644 --- a/copyparty/web/opds.xml +++ b/copyparty/web/opds.xml @@ -1,10 +1,13 @@ + {{ opds_id }} + {{ opds_title | e }} {%- for d in dirs %} + {{ d.opds_id }} {{ d.name | e }} + {{ f.opds_id }} {{ f.name | e }} {{ f.iso8601 }}