diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-07-16 20:27:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-07-16 20:27:53 +0200 |
commit | cfc9ef1cade470f6d2a7ba67c625eb8c11ff2743 (patch) | |
tree | cab15e6b04b8773d98ed5165ab3efca3775e5f4f /src/rss_html_common.c | |
parent | b3ef5d250c3cc4e35e82812bfd29fb19eb9bba83 (diff) |
Add fallback urls for rss (right now, fallback nyaa.si to nyaa.land)
Diffstat (limited to 'src/rss_html_common.c')
-rw-r--r-- | src/rss_html_common.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/rss_html_common.c b/src/rss_html_common.c index e5e44ab..c210452 100644 --- a/src/rss_html_common.c +++ b/src/rss_html_common.c @@ -1,4 +1,5 @@ #include "rss_html_common.h" +#include "fallback.h" #include "../depends/cJSON.h" #include "fileutils.h" #include <string.h> @@ -7,7 +8,7 @@ #include <time.h> #include <assert.h> -int write_plugin_json_to_file(const char *dir, const char *filename, const char *url, const char *updated, DownloadItemsData *prev_download_items, size_t num_prev_download_items, const char *plugin_name) { +int write_plugin_json_to_file(const char *dir, const char *filename, const char *url, const char *updated, DownloadItemsData *prev_download_items, size_t num_prev_download_items, const char *plugin_name, fallback *fall) { int result = 0; cJSON *json_body = cJSON_CreateObject(); @@ -35,12 +36,17 @@ int write_plugin_json_to_file(const char *dir, const char *filename, const char goto cleanup; } + char new_url[2048]; + snprintf(new_url, sizeof(new_url), "%s", prev_download_items[i].link); + if(fall) + fallback_replace_active_fallback_url_with_source_url(fall, prev_download_items[i].link, new_url, sizeof(new_url)); + char item_created_timestamp_fake[32]; snprintf(item_created_timestamp_fake, sizeof(item_created_timestamp_fake), "%ld", time_now - i); cJSON_AddStringToObject(downloaded_item_json, "title", prev_download_items[i].title); cJSON_AddStringToObject(downloaded_item_json, "time", item_created_timestamp_fake); - cJSON_AddStringToObject(downloaded_item_json, "url", prev_download_items[i].link); + cJSON_AddStringToObject(downloaded_item_json, "url", new_url); cJSON_AddBoolToObject(downloaded_item_json, "filler", 1); cJSON_AddItemToArray(downloaded_json, downloaded_item_json); @@ -72,7 +78,7 @@ static long timestamps_get_max(long *timestamps, size_t num_timestamps) { } /* TODO: If this fails in the middle, recover and update the next time somehow */ -int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, long *timestamps, int num_download_items) { +int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, DownloadItemsData **download_items, char **filenames, long *timestamps, int num_download_items, fallback *fall) { if(num_download_items == 0) return 0; @@ -116,12 +122,17 @@ int tracked_item_update_latest(TrackedItem *tracked_item, char *tracked_dir, Dow goto cleanup; } + char new_url[2048]; + snprintf(new_url, sizeof(new_url), "%s", download_items[i]->link); + if(fall) + fallback_replace_active_fallback_url_with_source_url(fall, download_items[i]->link, new_url, sizeof(new_url)); + char timestamp[32]; snprintf(timestamp, sizeof(timestamp), "%ld", timestamps[i]); cJSON_AddStringToObject(downloaded_item_json, "title", download_items[i]->title); cJSON_AddStringToObject(downloaded_item_json, "time", timestamp); - cJSON_AddStringToObject(downloaded_item_json, "url", download_items[i]->link); + cJSON_AddStringToObject(downloaded_item_json, "url", new_url); if(filenames) cJSON_AddStringToObject(downloaded_item_json, "filename", filenames[i]); |