Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,12 @@ url parameters:
* `n` = filename
* `a` = filesize
* uppercase = reverse-sort; `M` = oldest file first
* `rss-title-format={title}` format for RSS item titles, using tags or metadata (can also be set globally with `--rss-title-format`)
* available placeholders: `{title}`, `{artist}`, `{album}`, `{.tn}`, `{date}`, `{filename}`
* default: `{filename}`
* `rss-desc-format={artist} - {title}` format for RSS item descriptions, using tags or metadata (can also be set globally with `--rss-desc-format`)
* available placeholders: `{title}`, `{artist}`, `{album}`, `{.tn}`, `{date}`, `{filename}`
* default: `{filename}`


## opds feeds
Expand Down
2 changes: 2 additions & 0 deletions copyparty/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,8 @@ def add_rss(ap):
ap2.add_argument("--rss-nf", metavar="HITS", type=int, default=250, help="default number of files to return (url-param 'nf')")
ap2.add_argument("--rss-fext", metavar="E,E", type=u, default="", help="default list of file extensions to include (url-param 'fext'); blank=all")
ap2.add_argument("--rss-sort", metavar="ORD", type=u, default="m", help="default sort order (url-param 'sort'); [\033[32mm\033[0m]=last-modified [\033[32mu\033[0m]=upload-time [\033[32mn\033[0m]=filename [\033[32ms\033[0m]=filesize; Uppercase=oldest-first. Note that upload-time is 0 for non-uploaded files")
ap2.add_argument("--rss-title-format", metavar="FMT", type=u, default="{filename}", help="format for RSS item title; available tags: {title}, {artist}, {album}, {.tn}, {date}, {filename}; default is '{title}' (falls back to filename if tag missing)")
ap2.add_argument("--rss-desc-format", metavar="FMT", type=u, default="{filename}", help="format for RSS item description; available tags: {title}, {artist}, {album}, {.tn}, {date}, {filename}; default is '{artist} - {title}' (falls back to filename if all tags missing)")


def add_db_general(ap, hcores):
Expand Down
42 changes: 36 additions & 6 deletions copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,19 +1540,49 @@ def tx_rss(self) -> bool:
ap = ""
use_magic = "rmagic" in self.vn.flags

# Get format templates from config or URL params
title_fmt = self.uparam.get("rss-title-format", self.args.rss_title_format)
desc_fmt = self.uparam.get("rss-desc-format", self.args.rss_desc_format)

for i in hits:
if use_magic:
ap = os.path.join(self.vn.realpath, i["rp"])

iurl = html_escape("%s%s" % (baseurl, i["rp"]), True, True)
title = unquotep(i["rp"].split("?")[0].split("/")[-1])
fn_title = unquotep(i["rp"].split("?")[0].split("/")[-1])
fn_title_esc = html_escape(fn_title, True, True)

# Build tag dictionary for substitution
tag_dict = {
"filename": fn_title,
"title": str(i["tags"].get("title") or ""),
"artist": str(i["tags"].get("artist") or ""),
"album": str(i["tags"].get("album") or ""),
".tn": str(i["tags"].get(".tn") or ""),
"date": str(i["tags"].get("date") or ""),
}

# Format title using template
title = title_fmt
for tag_name, tag_value in tag_dict.items():
title = title.replace("{" + tag_name + "}", tag_value)
# If title is empty or only contains empty placeholders, use filename
if not title.strip() or title == title_fmt:
title = fn_title
title = html_escape(title, True, True)
tag_t = str(i["tags"].get("title") or "")
tag_a = str(i["tags"].get("artist") or "")
desc = "%s - %s" % (tag_a, tag_t) if tag_t and tag_a else (tag_t or tag_a)
desc = html_escape(desc, True, True) if desc else title
mime = html_escape(guess_mime(title, ap))

# Format description using template
desc = desc_fmt
for tag_name, tag_value in tag_dict.items():
desc = desc.replace("{" + tag_name + "}", tag_value)
# If desc is empty or only contains empty placeholders, use filename
if not desc.strip() or desc == desc_fmt:
desc = fn_title
desc = html_escape(desc, True, True)

mime = html_escape(guess_mime(fn_title, ap))
lmod = formatdate(max(0, i["ts"]))

zsa = (iurl, iurl, title, desc, lmod, iurl, mime, i["sz"])
zs = (
"""\
Expand Down
2 changes: 1 addition & 1 deletion copyparty/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _add_mimes() -> None:

DEF_EXP = "self.ip self.ua self.uname self.host cfg.name cfg.logout vf.scan vf.thsize hdr.cf-ipcountry srv.itime srv.htime"

DEF_MTE = ".files,circle,album,.tn,artist,title,.bpm,key,.dur,.q,.vq,.aq,vc,ac,fmt,res,.fps,ahash,vhash"
DEF_MTE = ".files,circle,album,.tn,artist,title,date,.bpm,key,.dur,.q,.vq,.aq,vc,ac,fmt,res,.fps,ahash,vhash"

DEF_MTH = ".vq,.aq,vc,ac,fmt,res,.fps"

Expand Down