Added support for multiple regexs for valid episode names, and decrappify'ing regex (to remove valid, but non-video files)

This commit is contained in:
dbr
2008-04-27 21:35:36 +09:30
parent 439f656236
commit bb72e60361

View File

@@ -36,12 +36,17 @@ def colour(text,colour="red"):
# Show name - [01x23] - The Episode Name (Part 1) # Show name - [01x23] - The Episode Name (Part 1)
# Show name - [01x23] - The Episode Name # Show name - [01x23] - The Episode Name
# Show name - [04x01] # Show name - [04x01]
tv_ep_name = re.compile("([-\w ]+) - \[(\d{2})x(\d{2}|\d{2}-\d{2})\](?= - ([\w\(\) ]+))?") tv_ep_name = [
re.compile("([-\w ]+) - \[(\d{2})x(\d{2}|\d{2}-\d{2})\](?= - ([\w\(\) ]+))?"),
]
################################### ###################################
# Regex to match valid, but not-to-be-processed files (dot-files, folder.jpg artwork) # Regex to match valid, but not-to-be-processed files (dot-files, folder.jpg artwork)
################################### ###################################
decrappify = re.compile("(?=^[.]{1}.*|folder.jpg)") decrappify = [
re.compile("(?=^[.]{1}.*)"),
re.compile("folder.jpg"),
]
# Location to process # Location to process
loc = "." # Runs from the current path loc = "." # Runs from the current path
@@ -53,16 +58,22 @@ loc = "." # Runs from the current path
#TODO: Array of valid extensions (not just .avi) #TODO: Array of valid extensions (not just .avi)
import path import path
d = path.path(loc) d = path.path(loc)
list=[] allfiles=[]
for f in d.walkfiles("*.avi"): for f in d.walkfiles("*"):
list.append( str(f) ) allfiles.append( str(f) )
#end for f
#Old, non-recursive version (that doesn't need the path.py module): files = [x for x in allfiles if os.path.isfile(x)] # only get files, not folders
#list = os.listdir(loc) # list dir
list = [x for x in list if decrappify.match(x)] # Strip out dotfiles/folder.jpg # Strip out dotfiles/folder.jpg
list = [os.path.join(loc,x) for x in list] # append path to file name for current_file in allfiles:
files = [x for x in list if os.path.isfile(x)] # only get files, not folders current_file_path,current_file_name = os.path.split(current_file)
for cur_decrap in decrappify:
if cur_decrap.match(current_file_name):
files.remove(current_file)
#end for file
#files = [os.path.join(loc,x) for x in files] # append path to file name
# Warn if no files are found, then exit # Warn if no files are found, then exit
if files.__len__() == 0: if files.__len__() == 0:
@@ -77,14 +88,17 @@ valid = []
invalid = [] invalid = []
for cur in files: for cur in files:
check = tv_ep_name.findall(cur) for cur_checker in tv_ep_name:
if check: check = cur_checker.findall(cur)
# Valid file name if check:
valid.append(check) # Valid file name
valid.append(check)
break # Found valid episode, skip to the next one
#end if
else: else:
# Invalid name # No match found (Invalid name)
invalid.append(cur) invalid.append(cur)
#end if #end for cur_checker
#end for #end for
################################### ###################################