Python 2.6 tvsort bug (fix inside)

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
Posts: 6
Joined: December 1st, 2009, 5:39 am

Python 2.6 tvsort bug (fix inside)

Post by cj_ » December 5th, 2009, 10:43 am

Found another bug that results in post processing crash with the following traceback:

Code: Select all

  File "/home/cjones/local/usenet/sabnzbd/", line 630, in check_for_multiple
    regex = re.compile(regex, re.I)
  File "/usr/lib/python2.6/", line 190, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.6/", line 238, in _compile
    raise ValueError('Cannot process flags argument with a compiled pattern')
ValueError: Cannot process flags argument with a compiled pattern
The culprit is trying to re-compile an already compiled regex, which does not work in python 2.6:

Code: Select all

621:     def check_for_multiple(self, files):
622:         expressions = []
623:         matched_files = []
625:         expressions.append(re.compile('cd\W?(\d)\W', re.I)) # .cd1.avi
626:         expressions.append(re.compile('\w\W?([\w\d])$', re.I)) # blah1.avi blaha.avi
627:         expressions.append(re.compile('\w\W([\w\d])\W', re.I)) # blah-1-ok.avi blah-a-ok.avi
629:         for regex in expressions:
630:             regex = re.compile(regex, re.I)
631:             matched_files = check_for_sequence(regex, files)
632:             if matched_files:
633:                 return matched_files
634:         return ''
Even though this works in python 2.5, there is no need to compile twice.  I would either remove line 630, or not compile in 625-627.  The function could probably be better written like so:

Code: Select all

def check_for_multiple(self, files):
    for regex in r'cd\W?(\d)\W', r'\w\W?([\w\d])$', r'\w\W([\w\d])\W':
        matched_files = check_for_sequence(re.compile(regex, re.I), files)
        if matched_files:
            return matched_files
    return ''
Last edited by cj_ on December 5th, 2009, 10:57 am, edited 1 time in total.

Posts: 6
Joined: December 1st, 2009, 5:39 am

Re: Python 2.6 tvsort bug (fix inside)

Post by cj_ » December 5th, 2009, 11:04 am

Oh, one other bug in the same module.  No fix here, but you might want to look at it.  Using a sort string like this:


Doesn't work right.  The reason is that before the code converts {} to lowercase and strips it out, it does this:

if path.endswith('%ext'):

Since the path does not actually end with %ext (it ends with "%ext}"), it behaves as if this were a directory.  %e gets replace with the episode number, so you end up with a directory structure like this:

.. which is suboptimal.  There are a few ways to fix this.  Maybe use a regex that allows for both cases, like: %ext}?$

User avatar
Posts: 21036
Joined: January 18th, 2008, 12:49 pm

Re: Python 2.6 tvsort bug (fix inside)

Post by shypike » December 5th, 2009, 11:32 am

I need to speak to the tvsort designer...

Post Reply