webui: handle RSS link torrent URLs

This commit is contained in:
ookami125 2026-06-23 02:12:53 -04:00
parent 0249ce330d
commit 15905c2f35
2 changed files with 18 additions and 6 deletions

View file

@ -2094,6 +2094,8 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new
char enclosure[1024] = {0}, lenstr[64] = {0}, pub[128] = {0};
xml_tag_text(open, ilen, "title", title, sizeof title);
xml_tag_text(open, ilen, "link", link, sizeof link);
/* Atom (and some RSS) carry the URL as <link href="..."> instead. */
if (!link[0]) xml_attr(open, ilen, "link", "href", link, sizeof link);
xml_tag_text(open, ilen, "pubDate", pub, sizeof pub);
if (!pub[0]) xml_tag_text(open, ilen, "published", pub, sizeof pub);
find_magnet(open, ilen, magnet, sizeof magnet);
@ -2102,6 +2104,11 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new
xml_tag_text(open, ilen, "contentLength", lenstr, sizeof lenstr);
if (!magnet[0] && strncmp(link, "magnet:", 7) == 0)
snprintf(magnet, sizeof magnet, "%s", link);
/* A bare <link> to a .torrent is a valid download source too. */
char dl_url[1024] = {0};
if (enclosure[0]) snprintf(dl_url, sizeof dl_url, "%s", enclosure);
else if (strncmp(link, "http", 4) == 0 && strncmp(magnet, "magnet:", 7) != 0)
snprintf(dl_url, sizeof dl_url, "%s", link);
const char *key = magnet[0] ? magnet : (enclosure[0] ? enclosure : link);
if (title[0] && key && *key) {
@ -2112,9 +2119,9 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new
}
if (!seen) {
json_t *art = json_pack(
"{s:s,s:s,s:s,s:s,s:I,s:s,s:b,s:b}",
"{s:s,s:s,s:s,s:s,s:s,s:I,s:s,s:b,s:b}",
"title", title, "key", key,
"magnet", magnet, "torrentUrl", enclosure,
"magnet", magnet, "torrentUrl", dl_url, "link", link,
"size", (json_int_t)strtoll(lenstr, NULL, 10),
"pubDate", pub, "isRead", 0, "grabbed", 0);
json_array_insert_new(articles, 0, art);
@ -2122,7 +2129,7 @@ static int rss_ingest(json_t *feed, const char *xml, size_t len, json_t *out_new
if (out_new)
json_array_append_new(out_new, json_pack(
"{s:s,s:s,s:s,s:s}", "title", title, "key", key,
"magnet", magnet, "torrentUrl", enclosure));
"magnet", magnet, "torrentUrl", dl_url));
}
}
p = close + strlen(close_tag);