From cfc9ef1cade470f6d2a7ba67c625eb8c11ff2743 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 16 Jul 2024 20:27:53 +0200 Subject: Add fallback urls for rss (right now, fallback nyaa.si to nyaa.land) --- src/rss_html_common.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/rss_html_common.c') 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 @@ -7,7 +8,7 @@ #include #include -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]); -- cgit v1.2.3