From 521c2e58303616b607cbc4f6ca5d8e9bca94520c Mon Sep 17 00:00:00 2001 From: Carlos Quijano Date: Tue, 10 Feb 2015 09:47:38 +0100 Subject: [PATCH 1/4] add pattern replacement to folders --- include/feed_item.h | 2 +- src/automatic.c | 16 +++++++++++----- src/feed_item.c | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/feed_item.h b/include/feed_item.h index 1bf15ca..4020224 100644 --- a/include/feed_item.h +++ b/include/feed_item.h @@ -42,6 +42,6 @@ struct feed_item { void freeFeedItem(void *item); feed_item newFeedItem(void); -uint8_t isMatch(const simple_list filters, const char * string, const char * feedID, char **folder); +uint8_t isMatch(const simple_list filters, const char * string, const char * feedID, char **folder,char** filter_pattern); #endif diff --git a/src/automatic.c b/src/automatic.c index 84e2a5a..15cceef 100644 --- a/src/automatic.c +++ b/src/automatic.c @@ -528,7 +528,9 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp simple_list current_item = items; HTTPResponse *torrent = NULL; char fname[MAXPATHLEN]; - char *download_folder = NULL; + char *download_folder =NULL; + char *filter_pattern =NULL; + char *download_folder_reg =NULL; char *feedID = NULL; char *download_url = NULL; @@ -544,7 +546,7 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp while(current_item && current_item->data) { feed_item item = (feed_item)current_item->data; - if(isMatch(session->filters, item->name, feedID, &download_folder)) { + if(isMatch(session->filters, item->name, feedID, &download_folder, &filter_pattern)) {/*Fill forder from filter*/ if(!session->match_only) { if(has_been_downloaded(session->downloads, item)) { dbg_printf(P_INFO, "Duplicate torrent: %s", item->name); @@ -557,19 +559,23 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp // It's a torrent file // Rewrite torrent URL, if necessary if(feed->url_pattern != NULL && feed->url_replace != NULL) { - download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace); + download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace);/*Aqui se reescribe la url*/ + } + if(download_folder != NULL && filter_pattern != NULL) { + download_folder_reg = rewriteURL(item->name, filter_pattern, download_folder);/*Aqui se reescribe la url*/ + dbg_printft(P_MSG, "New Folder: [%s]->(%s)",download_folder , download_folder_reg ); } - torrent = downloadTorrent(curl_session, download_url != NULL ? download_url : item->url); if(torrent) { get_filename(fname, torrent->content_filename, item->url, session->torrent_folder); /* add torrent to Transmission */ - result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder); + result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder);/*Here We are*/ HTTPResponse_free(torrent); } am_free(download_url); + am_free(download_folder_reg); } // process result diff --git a/src/feed_item.c b/src/feed_item.c index 3d6fed2..99e0068 100644 --- a/src/feed_item.c +++ b/src/feed_item.c @@ -54,7 +54,7 @@ * \return 1 if a filter matched, 0 otherwise. * */ -uint8_t isMatch(const am_filters filters, const char * string, const char * feedID, char **folder) { +uint8_t isMatch(const am_filters filters, const char * string, const char * feedID, char **folder, char** filter_pattern) { am_filters current_regex = NULL; am_filter filter; @@ -73,6 +73,7 @@ uint8_t isMatch(const am_filters filters, const char * string, const char * feed if( !(filter->feedID && *filter->feedID) || (feedID && *feedID && strcasecmp(feedID, filter->feedID) == 0)) { if(isRegExMatch(filter->pattern, string) == 1) { *folder = filter->folder; + *filter_pattern = filter->pattern; return 1; } } From b3a4bdbb455c5b8fb7e3fcf05c3a1b23dbc41a1e Mon Sep 17 00:00:00 2001 From: Carlos Quijano Date: Tue, 10 Feb 2015 19:21:02 +0100 Subject: [PATCH 2/4] added mkdir functions for directories --- src/automatic.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/automatic.c b/src/automatic.c index 2d14300..a05b948 100644 --- a/src/automatic.c +++ b/src/automatic.c @@ -540,6 +540,15 @@ PRIVATE int8_t addMagnetToTM(const auto_handle *ah, const char* magnet_uri, cons /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// +PRIVATE void createDIR(const char* directory) { + struct stat s; + if (stat(directory, &s) == -1) { + return mkdir(directory, 0700); + } + return 0;/*No error*/ +} + + PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simple_list items, const rss_feed * feed) { simple_list current_item = items; HTTPResponse *torrent = NULL; @@ -575,18 +584,19 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp // It's a torrent file // Rewrite torrent URL, if necessary if(feed->url_pattern != NULL && feed->url_replace != NULL) { - download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace);/*Aqui se reescribe la url*/ + download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace); } if(download_folder != NULL && filter_pattern != NULL) { - download_folder_reg = rewriteURL(item->name, filter_pattern, download_folder);/*Aqui se reescribe la url*/ + download_folder_reg = rewriteURL(item->name, filter_pattern, download_folder); dbg_printft(P_MSG, "New Folder: [%s]->(%s)",download_folder , download_folder_reg ); + createDIR(download_folder_reg); } torrent = downloadTorrent(curl_session, download_url != NULL ? download_url : item->url); if(torrent) { get_filename(fname, torrent->content_filename, item->url, session->torrent_folder); /* add torrent to Transmission */ - result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder);/*Here We are*/ + result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder); HTTPResponse_free(torrent); } From cb58545b218e976196a7a55fc0e13f96d3ef8291 Mon Sep 17 00:00:00 2001 From: Carlos Quijano Date: Wed, 11 Feb 2015 15:26:57 +0100 Subject: [PATCH 3/4] fix folder sendig to transmission --- src/automatic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/automatic.c b/src/automatic.c index a05b948..eaec0ca 100644 --- a/src/automatic.c +++ b/src/automatic.c @@ -596,7 +596,7 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp get_filename(fname, torrent->content_filename, item->url, session->torrent_folder); /* add torrent to Transmission */ - result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder); + result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder_reg ? download_folder_reg : download_folder); HTTPResponse_free(torrent); } From 4eb62ae0956ca203fbafcf8354c5842bd1a4cb21 Mon Sep 17 00:00:00 2001 From: Carlos Quijano Date: Tue, 17 Mar 2015 18:40:27 +0100 Subject: [PATCH 4/4] remove unneeded comments --- src/automatic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/automatic.c b/src/automatic.c index eaec0ca..2c74cc4 100644 --- a/src/automatic.c +++ b/src/automatic.c @@ -553,9 +553,9 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp simple_list current_item = items; HTTPResponse *torrent = NULL; char fname[MAXPATHLEN]; - char *download_folder =NULL; - char *filter_pattern =NULL; - char *download_folder_reg =NULL; + char *download_folder = NULL; + char *filter_pattern = NULL; + char *download_folder_reg = NULL; char *feedID = NULL; char *download_url = NULL; @@ -571,7 +571,7 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp while(current_item && current_item->data) { feed_item item = (feed_item)current_item->data; - if(isMatch(session->filters, item->name, feedID, &download_folder, &filter_pattern)) {/*Fill forder from filter*/ + if(isMatch(session->filters, item->name, feedID, &download_folder, &filter_pattern)) { if(!session->match_only) { if(has_been_downloaded(session->downloads, item)) { dbg_printf(P_INFO, "Duplicate torrent: %s", item->name);