Browse Source

Rewrite of sorting functions to cleanup and correct errors.

Closes #288 for trunk.
tags/0.6.0
shypike 16 years ago
parent
commit
a8c20ca196
  1. 93
      main/sabnzbd/nzbstuff.py

93
main/sabnzbd/nzbstuff.py

@ -1072,67 +1072,46 @@ class NzbObject(TryList):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def _nzf_cmp_date(nzf1, nzf2): def _nzf_get_filename(nzf):
subject1 = nzf1.get_subject().lower() # Return filename, if the filename not set, try the
subject2 = nzf2.get_subject().lower() # the full subject line instead. Can produce non-ideal results
name = nzf.get_filename()
par2_found = 0 if name:
ret = 0 return name.lower()
if 'vol' in subject1 and '.par2' in subject1:
par2_found += 1
ret -= 1
if 'vol' in subject2 and '.par2' in subject2:
par2_found += 1
ret += 1
if '.rar' in subject1 and not '.par' in subject2 and not '.rar' in subject2: #some nzbs dont get filename field populated, using subject instead
return -1 #nzf1 contained '.rar' nzf2 didnt. Move nzf1 up in the queue
if par2_found == 1:
return ret
else: else:
return cmp(nzf1.get_date(), nzf2.get_date()) return nzf.get_subject().lower()
def _nzf_cmp_name(nzf1, nzf2):
'''
The comparison will sort .par2 files to the top of the queue followed by .rar files,
they will then be sorted by name.
'''
#Try to use the filename if it can be extracted from the subject
subject1 = nzf1.get_filename()
subject2 = nzf2.get_filename()
#if the filename cannot be extracted, use the full subject line for comparison. Can produce non-ideal results def _nzf_cmp_date(nzf1, nzf2):
if subject1: # Compare files based on date, but give vol-par files preference
subject1 = subject1.lower() return _nzf_cmp_name(nzf1, nzf2, name=False)
else:
subject1 = nzf1.get_subject().lower()
def _nzf_cmp_name(nzf1, nzf2, name=True):
if subject2: # The comparison will sort .par2 files to the top of the queue followed by .rar files,
subject2 = subject2.lower() # they will then be sorted by name.
else: name1 = _nzf_get_filename(nzf1)
subject2 = nzf2.get_subject().lower() name2 = _nzf_get_filename(nzf2)
par2_found = 0 is_par1 = 'vol' in name1 and '.par2' in name1
ret = 0 is_par2 = 'vol' in name2 and '.par2' in name2
if 'vol' in subject1 and '.par2' in subject1: if is_par1 and not is_par2:
par2_found += 1 return -1
ret -= 1 if is_par2 and not is_par1:
return 1
if 'vol' in subject2 and '.par2' in subject2:
par2_found += 1 if name:
ret += 1 # Prioritise .rar files above any other type of file (other than vol-par)
# Useful for nzb streaming
#Prioritise .rar files above any other type of file (other than .par) if '.rar' in name1 and not is_par2 and '.rar' not in name2:
#Useful for nzb streaming return -1
if '.rar' in subject1 and not '.par' in subject2 and not '.rar' in subject2: #some nzbs dont get filename field populated, using subject instead elif '.rar' in name2 and not is_par1 and '.rar' not in name1:
return -1 #nzf1 contained '.rar' nzf2 didnt. Move nzf1 up in the queue return 1
if par2_found == 1: return cmp(name1, name2)
return ret
else: else:
return cmp(subject1, subject2) # Do date comparision
return cmp(nzf1.get_date(), nzf2.get_date())
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

Loading…
Cancel
Save