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
|
/* 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. */
|
* uploading its bytes. Applies category/save path/paused, mirrors the label. */
|
||||||
static bool rss_download(const char *magnet, const char *torrent_url,
|
static bool rss_download(const char *title, const char *magnet,
|
||||||
const char *category, const char *save_path,
|
const char *torrent_url, const char *category,
|
||||||
bool paused) {
|
const char *save_path, bool paused) {
|
||||||
json_t *params = json_object();
|
json_t *params = json_object();
|
||||||
if (!params) return false;
|
if (!params) return false;
|
||||||
json_object_set_new(params, "output",
|
json_object_set_new(params, "output",
|
||||||
json_string(save_path && *save_path ? save_path : "."));
|
json_string(save_path && *save_path ? save_path : "."));
|
||||||
if (paused) json_object_set_new(params, "paused", json_true());
|
if (paused) json_object_set_new(params, "paused", json_true());
|
||||||
if (category && *category) json_object_set_new(params, "category", json_string(category));
|
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;
|
char *fetched = NULL;
|
||||||
if (magnet && *magnet) {
|
if (magnet && *magnet) {
|
||||||
|
|
@ -1976,6 +1979,7 @@ static bool rss_download(const char *magnet, const char *torrent_url,
|
||||||
free(fetched);
|
free(fetched);
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
uint64_t id = json_u64(result, "torrent_id");
|
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);
|
if (id && category && *category) store_set_category(id, category);
|
||||||
json_decref(result);
|
json_decref(result);
|
||||||
publish_snapshot();
|
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. */
|
/* Download an article and, on success, flag it grabbed by key. */
|
||||||
static bool rss_grab_article(const char *key, const char *magnet,
|
static bool rss_grab_article(const char *key, const char *title,
|
||||||
const char *torrent_url, const char *cat,
|
const char *magnet, const char *torrent_url,
|
||||||
const char *path, bool paused) {
|
const char *cat, const char *path, bool paused) {
|
||||||
bool ok = rss_download(magnet, torrent_url, cat, path, paused);
|
bool ok = rss_download(title, magnet, torrent_url, cat, path, paused);
|
||||||
if (ok) rss_mark_grabbed(key);
|
if (ok) rss_mark_grabbed(key);
|
||||||
return ok;
|
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);
|
pthread_mutex_unlock(&g_webui.rss_lock);
|
||||||
if (!fire) return;
|
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");
|
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", "");
|
const char *url = json_string_or(a, "torrentUrl", "");
|
||||||
if (!*mag && !*url) continue;
|
if (!*mag && !*url) continue;
|
||||||
if (rule_matches(probe, fname, json_string_or(a, "title", "")))
|
if (rule_matches(probe, fname, json_string_or(a, "title", "")))
|
||||||
json_array_append_new(todo, json_pack("{s:s,s:s,s:s}",
|
json_array_append_new(todo, json_pack("{s:s,s:s,s:s,s:s}",
|
||||||
"key", json_string_or(a, "key", ""), "magnet", mag, "torrentUrl", url));
|
"key", json_string_or(a, "key", ""),
|
||||||
|
"title", json_string_or(a, "title", ""),
|
||||||
|
"magnet", mag, "torrentUrl", url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
json_decref(probe);
|
json_decref(probe);
|
||||||
|
|
@ -2343,7 +2349,8 @@ static void api_rss_rule_run(int fd, const char *body, size_t len) {
|
||||||
int grabbed = 0;
|
int grabbed = 0;
|
||||||
size_t j; json_t *t;
|
size_t j; json_t *t;
|
||||||
json_array_foreach(todo, j, 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))
|
json_string_or(t, "torrentUrl", ""), cat, path, paused))
|
||||||
grabbed++;
|
grabbed++;
|
||||||
size_t matched = json_array_size(todo);
|
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 *cat = json_string_or(req, "category", "");
|
||||||
const char *path = json_string_or(req, "savePath", "");
|
const char *path = json_string_or(req, "savePath", "");
|
||||||
const char *key = json_string_or(req, "key", "");
|
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 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 */
|
if (ok && *key) rss_save(); /* persist the grabbed flag */
|
||||||
json_decref(req);
|
json_decref(req);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue