All pastes #815955 Raw Edit

Stuff

public text v1 · immutable
·published 2007-12-14 14:58 UTC
rendered paste body
common_filename_patterns = [
	re.compile("^\d{2,3} - "), 			# ex "01 - Foo.mp3"
	re.compile("^\d{2,3} [^-]"), 		# ex "01 Foo.mp3"
	re.compile("^\d{1,2}-\d{2,3} "),	# ex "2-16 Foo.mp3" (used in iTunes multi-disc albums)
	re.compile("^\d{2,3}-") 			# ex "01-Foo.mp3"
]
def find_filenameconvention(files):
	winner = (0,None)
	for rx in common_filename_patterns:
		found = 0
		for filename in files:
			if rx.match(filename) != None:
				found += 1
		if found > winner[0]:
			winner = (found, rx)
	return winner