Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/feed_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 20 additions & 4 deletions src/automatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/feed_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand Down