@ -36,13 +36,14 @@ import re
from sabnzbd . filesystem import get_unique_filename , renamer , get_ext
from sabnzbd . par2file import is_parfile , parse_par2_file
import sabnzbd . utils . file_extension as file_extension
from typing import List
# Files to exclude and minimal file size for renaming
EXCLUDED_FILE_EXTS = ( " .vob " , " .rar " , " .par2 " , " .mts " , " .m2ts " , " .cpi " , " .clpi " , " .mpl " , " .mpls " , " .bdm " , " .bdmv " )
MIN_FILE_SIZE = 10 * 1024 * 1024
def decode_par2 ( parfile ) :
def decode_par2 ( parfile : str ) - > List [ str ] :
""" Parse a par2 file and rename files listed in the par2 to their real name. Resturn list of generated files """
# Check if really a par2 file
if not is_parfile ( parfile ) :
@ -74,7 +75,31 @@ def decode_par2(parfile):
return new_files
def is_probably_obfuscated ( myinputfilename ) :
def recover_par2_names ( filelist : List [ str ] ) - > List [ str ] :
""" Find par2 files and use them for renaming """
# Check that files exists
filelist = [ f for f in filelist if os . path . isfile ( f ) ]
# Search for par2 files in the filelist
par2_files = [ f for f in filelist if f . endswith ( " .par2 " ) ]
# Found any par2 files we can use?
if not par2_files :
logging . debug ( " No par2 files found to process, running renamer " )
else :
# Run par2 from SABnzbd on them
for par2_file in par2_files :
# Analyse data and analyse result
logging . debug ( " Deobfuscate par2: handling %s " , par2_file )
new_files = decode_par2 ( par2_file )
if new_files :
logging . debug ( " Deobfuscate par2 repair/verify finished " )
filelist + = new_files
filelist = [ f for f in filelist if os . path . isfile ( f ) ]
else :
logging . debug ( " Deobfuscate par2 repair/verify did not find anything to rename " )
return filelist
def is_probably_obfuscated ( myinputfilename : str ) - > bool :
""" Returns boolean if filename is likely obfuscated. Default: True
myinputfilename ( string ) can be a plain file name , or a full path """
@ -133,7 +158,7 @@ def is_probably_obfuscated(myinputfilename):
return True # default not obfuscated
def deobfuscate_list ( filelist , usefulname ) :
def deobfuscate_list ( filelist : List [ str ] , usefulname : str ) :
""" Check all files in filelist, and if wanted, deobfuscate: rename to filename based on usefulname """
# Methods
@ -144,25 +169,6 @@ def deobfuscate_list(filelist, usefulname):
# to be sure, only keep really exsiting files:
filelist = [ f for f in filelist if os . path . isfile ( f ) ]
# Search for par2 files in the filelist
par2_files = [ f for f in filelist if f . endswith ( " .par2 " ) ]
# Found any par2 files we can use?
par2_renaming_done = False
if not par2_files :
logging . debug ( " No par2 files found to process, running renamer " )
else :
# Run par2 from SABnzbd on them
for par2_file in par2_files :
# Analyse data and analyse result
logging . debug ( " Deobfuscate par2: handling %s " , par2_file )
new_files = decode_par2 ( par2_file )
if new_files :
logging . debug ( " Deobfuscate par2 repair/verify finished " )
filelist + = new_files
filelist = [ f for f in filelist if os . path . isfile ( f ) ]
else :
logging . debug ( " Deobfuscate par2 repair/verify did not find anything to rename " )
# let's see if there are files with uncommon/unpopular (so: obfuscated) extensions
# if so, let's give them a better extension based on their internal content/info
# Example: if 'kjladsflkjadf.adsflkjads' is probably a PNG, rename to 'kjladsflkjadf.adsflkjads.png'