webui: name RSS downloads after the article title
Auto/manual RSS downloads now forward the article (or search result) title as the torrent's display name, so fetched .torrent enclosures no longer show as "upload-XXXXXX". Threaded the title through rss_download / rss_grab_article and set the web-layer display name on success. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
66ec5d6c3d
commit
ab733cb573
1 changed files with 20 additions and 12 deletions
|
|
@ -1942,15 +1942,18 @@ static void rss_load(void) {
|
|||
|
||||
/* Add a torrent from a magnet, or by fetching a .torrent enclosure URL and
|
||||
* uploading its bytes. Applies category/save path/paused, mirrors the label. */
|
||||
static bool rss_download(const char *magnet, const char *torrent_url,
|
||||
const char *category, const char *save_path,
|
||||
bool paused) {
|
||||
static bool rss_download(const char *title, const char *magnet,
|
||||
const char *torrent_url, const char *category,
|
||||
const char *save_path, bool paused) {
|
||||
json_t *params = json_object();
|
||||
if (!params) return false;
|
||||
json_object_set_new(params, "output",
|
||||
json_string(save_path && *save_path ? save_path : "."));
|
||||
if (paused) json_object_set_new(params, "paused", json_true());
|
||||
if (category && *category) json_object_set_new(params, "category", json_string(category));
|
||||
/* The article title is the real torrent name; without it the daemon falls
|
||||
* back to the temp upload filename (upload-XXXXXX) for fetched .torrents. */
|
||||
if (title && *title) json_object_set_new(params, "name", json_string(title));
|
||||
|
||||
char *fetched = NULL;
|
||||
if (magnet && *magnet) {
|
||||
|
|
@ -1976,6 +1979,7 @@ static bool rss_download(const char *magnet, const char *torrent_url,
|
|||
free(fetched);
|
||||
if (!result) return false;
|
||||
uint64_t id = json_u64(result, "torrent_id");
|
||||
if (id && title && *title) store_set_name(id, title);
|
||||
if (id && category && *category) store_set_category(id, category);
|
||||
json_decref(result);
|
||||
publish_snapshot();
|
||||
|
|
@ -2036,10 +2040,10 @@ static void rss_mark_grabbed(const char *key) {
|
|||
}
|
||||
|
||||
/* Download an article and, on success, flag it grabbed by key. */
|
||||
static bool rss_grab_article(const char *key, const char *magnet,
|
||||
const char *torrent_url, const char *cat,
|
||||
const char *path, bool paused) {
|
||||
bool ok = rss_download(magnet, torrent_url, cat, path, paused);
|
||||
static bool rss_grab_article(const char *key, const char *title,
|
||||
const char *magnet, const char *torrent_url,
|
||||
const char *cat, const char *path, bool paused) {
|
||||
bool ok = rss_download(title, magnet, torrent_url, cat, path, paused);
|
||||
if (ok) rss_mark_grabbed(key);
|
||||
return ok;
|
||||
}
|
||||
|
|
@ -2063,7 +2067,7 @@ static void rss_run_rules(const char *feed_name, const char *key,
|
|||
}
|
||||
pthread_mutex_unlock(&g_webui.rss_lock);
|
||||
if (!fire) return;
|
||||
if (rss_grab_article(key, magnet, torrent_url, cat, path, paused))
|
||||
if (rss_grab_article(key, title, magnet, torrent_url, cat, path, paused))
|
||||
log_msg(2, "rss: auto-downloaded a match");
|
||||
}
|
||||
|
||||
|
|
@ -2328,8 +2332,10 @@ static void api_rss_rule_run(int fd, const char *body, size_t len) {
|
|||
const char *url = json_string_or(a, "torrentUrl", "");
|
||||
if (!*mag && !*url) continue;
|
||||
if (rule_matches(probe, fname, json_string_or(a, "title", "")))
|
||||
json_array_append_new(todo, json_pack("{s:s,s:s,s:s}",
|
||||
"key", json_string_or(a, "key", ""), "magnet", mag, "torrentUrl", url));
|
||||
json_array_append_new(todo, json_pack("{s:s,s:s,s:s,s:s}",
|
||||
"key", json_string_or(a, "key", ""),
|
||||
"title", json_string_or(a, "title", ""),
|
||||
"magnet", mag, "torrentUrl", url));
|
||||
}
|
||||
}
|
||||
json_decref(probe);
|
||||
|
|
@ -2343,7 +2349,8 @@ static void api_rss_rule_run(int fd, const char *body, size_t len) {
|
|||
int grabbed = 0;
|
||||
size_t j; json_t *t;
|
||||
json_array_foreach(todo, j, t)
|
||||
if (rss_grab_article(json_string_or(t, "key", ""), json_string_or(t, "magnet", ""),
|
||||
if (rss_grab_article(json_string_or(t, "key", ""), json_string_or(t, "title", ""),
|
||||
json_string_or(t, "magnet", ""),
|
||||
json_string_or(t, "torrentUrl", ""), cat, path, paused))
|
||||
grabbed++;
|
||||
size_t matched = json_array_size(todo);
|
||||
|
|
@ -2367,8 +2374,9 @@ static void api_rss_download(int fd, const char *body, size_t len) {
|
|||
const char *cat = json_string_or(req, "category", "");
|
||||
const char *path = json_string_or(req, "savePath", "");
|
||||
const char *key = json_string_or(req, "key", "");
|
||||
const char *title = json_string_or(req, "title", "");
|
||||
bool paused = json_boolean_value(json_object_get(req, "paused"));
|
||||
bool ok = rss_grab_article(key, magnet, url, cat, path, paused);
|
||||
bool ok = rss_grab_article(key, title, magnet, url, cat, path, paused);
|
||||
if (ok && *key) rss_save(); /* persist the grabbed flag */
|
||||
json_decref(req);
|
||||
if (ok) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue