Python 2.6 tvsort bug (fix inside)

Report & discuss bugs found in SABnzbd

Python 2.6 tvsort bug (fix inside)

Postby cj_ » December 5th, 2009, 11:43 am

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

Code: Select all
  File "/home/cjones/local/usenet/sabnzbd/tvsort.py", line 630, in check_for_multiple
    regex = re.compile(regex, re.I)
  File "/usr/lib/python2.6/re.py", line 190, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python2.6/re.py", 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 = []
624:
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
628:
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, 11:57 am, edited 1 time in total.
cj_
Newbie
Newbie
 
Posts: 6
Joined: December 1st, 2009, 6:39 am

Re: Python 2.6 tvsort bug (fix inside)

Postby cj_ » December 5th, 2009, 12:04 pm

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:

{%s.n.%ext}

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:

show.name.1xt/OrignalFilename.avi

.. which is suboptimal.  There are a few ways to fix this.  Maybe use a regex that allows for both cases, like: %ext}?$
cj_
Newbie
Newbie
 
Posts: 6
Joined: December 1st, 2009, 6:39 am

Re: Python 2.6 tvsort bug (fix inside)

Postby shypike » December 5th, 2009, 12:32 pm

Thanks.
I need to speak to the tvsort designer...
User avatar
shypike
Administrator
Administrator
 
Posts: 18043
Joined: January 18th, 2008, 1:49 pm


Return to Bug Reports