Page 1 of 1

[0.7.11] RequireCat not working in RSS feed

Posted: April 22nd, 2013, 4:37 am
by Commodore
because it's missing some code

made the following changes to rss.py to fix it:

Code: Select all

@@ -418,20 +418,22 @@
                     for n in xrange(regcount):
                         if reEnabled[n]:
                             if category and reTypes[n] == 'C':
-                                found = re.search(regexes[n], category)
+                               found = regexes[n].search(category)
                                 if not found:
-                                    logging.debug("Filter rejected on rule %d", n)
+                                    logging.debug("Filter unmatched on rule %d", n)
                                     result = False
+                                else:
+                                    logging.debug("Filter matched on rule %d", n)
+                                    result = True
                                     break
                             else:
                                 if regexes[n]:
-                                    found = re.search(regexes[n], title)
+                                    found = regexes[n].search(title)
                                 else:
                                     found = False
                                 if reTypes[n] == 'M' and not found:
-                                    logging.debug("Filter rejected on rule %d", n)
+                                    logging.debug("Filter unmatched on rule %d", n)
                                     result = False
-                                    break
                                 if found and reTypes[n] == 'A':
                                     logging.debug("Filter matched on rule %d", n)
                                     result = True
The changes here solve three problems:

- without the additional "else", RequiresCat rules that pass are never counted.
- some of the "break" statements prevent rule fallthrough where it should not be prevented (in the previous code, only the first rule would ever be evaluated because it would "break" on a failure to match)
- it is unnecessary to use re.search because regexes[n] is already a compiled re object, so regexes[n].search is better.

Re: [0.7.11] RequireCat not working in RSS feed

Posted: April 22nd, 2013, 12:55 pm
by shypike
You misunderstand the meaning of RequireCat.
It will only ever trigger on a mismatch. When it matches, the next filter is tried.
This by design.
You "require" category "TV", but after that your show name filter comes.
Any item not being category "TV" is rejected immediately. Otherwise any "TV" show would download.

Using re.search vs. regexes[n].search is arbitrary, the re.search functions knows that it getting a pre-compiled regex.
It is indeed more common to use the regex.search form.