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 ae95da7..2c74cc4 100644 --- a/src/automatic.c +++ b/src/automatic.c @@ -540,11 +540,22 @@ 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; char fname[MAXPATHLEN]; char *download_folder = NULL; + char *filter_pattern = NULL; + char *download_folder_reg = NULL; char *feedID = NULL; char *download_url = NULL; @@ -560,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)) { + 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); @@ -572,20 +583,25 @@ PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simp } else { // It's a torrent file // Rewrite torrent URL, if necessary - if((feed != NULL) && (feed->url_pattern != NULL) && (feed->url_replace != NULL)) { + if(feed->url_pattern != NULL && feed->url_replace != NULL) { 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); + 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); + result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder_reg ? download_folder_reg : download_folder); 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; } }