Small improvement to NZB sort
Posted: October 13th, 2010, 5:15 pm
Hi all,
I've made a small improvement to how sabnzbd sorts nzb files.
At the moment sabnzbd sorts an arbitrary set of example files in the following order:
video1.par2
video2.par2
video3.par2
video1.rar
video2.rar
video3.rar
video1.r01
video1.r02
video1.r03
video2.r01
video2.r02
video2.r03
video3.r01
video3.r02
video3.r03
There are obvious problems with this order.
For example streaming of video1 cannot begin until video3.rar has been downloaded.
Of course with 20 or more video files the delay can be significant.
A small change to nzbstuff.py:
Current Version:
My Version:
MY SORT ORDER:
video1.par2
video1.rar
video1.r01
video1.r02
video1.r03
video2.par2
video2.rar
video2.r01
video2.r02
video2.r03
video3.par2
video3.rar
video3.r01
video3.r02
video3.r03
The disadvantage to my version is that extra par2 files will end up being processed with the files that they are related to which means that sabnzbd will continue to include them in its download estimate until it gets to them.
I do not think that this is a major drawback but if others disagree the fix is trivial, simply swap out the par2 code in my version with the old version.
Anyway let me know what you think.
I've made a small improvement to how sabnzbd sorts nzb files.
At the moment sabnzbd sorts an arbitrary set of example files in the following order:
video1.par2
video2.par2
video3.par2
video1.rar
video2.rar
video3.rar
video1.r01
video1.r02
video1.r03
video2.r01
video2.r02
video2.r03
video3.r01
video3.r02
video3.r03
There are obvious problems with this order.
For example streaming of video1 cannot begin until video3.rar has been downloaded.
Of course with 20 or more video files the delay can be significant.
A small change to nzbstuff.py:
Current Version:
Code: Select all
def _nzf_cmp_name(nzf1, nzf2, name=True):
# The comparison will give priority to .par2 and .rar files after sorting by name
name1 = _nzf_get_filename(nzf1)
name2 = _nzf_get_filename(nzf2)
is_par1 = 'vol' in name1 and '.par2' in name1
is_par2 = 'vol' in name2 and '.par2' in name2
if is_par1 and not is_par2:
return -1
if is_par2 and not is_par1:
return 1
if name:
# Prioritise .rar files above any other type of file (other than vol-par)
# Useful for nzb streaming
if '.rar' in name1 and not is_par2 and '.rar' not in name2:
return -1
elif '.rar' in name2 and not is_par1 and '.rar' not in name1:
return 1
return cmp(name1, name2)
else:
# Do date comparision
return cmp(nzf1.get_date(), nzf2.get_date())
Code: Select all
def _nzf_cmp_name(nzf1, nzf2, name=True):
if name:
# The comparison will sort .par2 files to the top of the queue followed by .rar files,
# they will then be sorted by name.
name1 = _nzf_get_filename(nzf1)
name2 = _nzf_get_filename(nzf2)
#par2 get top priority
name1 = name1.replace('par2', '')
name2 = name2.replace('par2','')
#rar get priority after par2
#useful for nzb streaming
name1 = name1.replace('rar', '0')
name2 = name2.replace('rar', '0')
return cmp(name1, name2)
else:
# Do date comparision
return cmp(nzf1.get_date(), nzf2.get_date())
video1.par2
video1.rar
video1.r01
video1.r02
video1.r03
video2.par2
video2.rar
video2.r01
video2.r02
video2.r03
video3.par2
video3.rar
video3.r01
video3.r02
video3.r03
The disadvantage to my version is that extra par2 files will end up being processed with the files that they are related to which means that sabnzbd will continue to include them in its download estimate until it gets to them.
I do not think that this is a major drawback but if others disagree the fix is trivial, simply swap out the par2 code in my version with the old version.
Anyway let me know what you think.