import re

import trackWithError

def main():
	errorFile = open('samples/foobar2000-errors.txt', 'r')
	errors = errorFile.readlines()
	errorsDict = {}

	index = -1
	for i in range(len(errors)):
		line = errors[i]
		if re.search(r'List of undecodable items:', line):
			index = i
			break

	nbErrorsFoobar = 0
	for i in range(index, len(errors)):
		line = errors[i]
		match = re.search(r'[^".]+\\.+\\([^\\]+.flac)', line)
		if match:
			trackName = match.group(1)
			error = trackWithError.TrackWithError(trackName, match.group())
			if trackName in errorsDict:
				error = errorsDict.get(trackName)
				error.addCount()
			errorsDict[trackName] = error
			nbErrorsFoobar += 1

	errorFile.close()

	errorFile = open('samples/dbpoweramp-errors.txt', 'r')
	errors = errorFile.readlines()

	index = -1
	nbErrorsDbPowerAmp = 0
	for i in range(len(errors)):
		line = errors[i]
		match = re.search(r'/.+/([^/]+.flac)', line)
		if match:
			trackName = match.group(1)
			error = trackWithError.TrackWithError(trackName, match.group())
			if trackName in errorsDict:
				error = errorsDict.get(trackName)
				error.addCount()
			errorsDict[trackName] = error
		if (re.search(r'Encountered', line) or re.search(r'md5 did not match decoded data, file is corrupt.', line)):
			nbErrorsDbPowerAmp += 1

	errorFile.close()

	print(nbErrorsFoobar, 'FLAC errors from foobar2000')
	print(nbErrorsDbPowerAmp, 'FLAC errors from dbPowerAmp')
	print(len(errorsDict))

	errorFile = open('samples/results.txt', 'w')
	errorFile.write('Track name;Path;Count;\n')
	for k, v in errorsDict.items():
		errorFile.write(k + ';' + v.path + ';' + str(v.count) + ';\n')

if __name__ == "__main__":
	main()

@@ -1,12 +1,102 @@
+#!/usr/bin/env python%0A%0A'''%0AFind the errors in reports from foobar2000 and dbPowerAmp%0A'''%0A%0A
 import re%0A%0Ai
@@ -901,24 +901,62 @@
 owerAmp = 0%0A
+%09previousLineStartsWithSpaces = False%0A
 %09for i in ra
@@ -984,32 +984,74 @@
 ine = errors%5Bi%5D%0A
+%09%09if re.search(r'%5E%5Cs%7B3%7D', line) == None:%0A%09
 %09%09match = re.sea
@@ -1060,15 +1060,18 @@
 h(r'
+%5C
 /.+
+%5C
 /(%5B%5E
+%5C
 /%5D+.
@@ -1086,32 +1086,142 @@
 line)%0A%09%09if match
+ and (re.search(r'Encountered', line) or re.search(r'md5 did not match decoded data, file is corrupt.', line))
 :%0A%09%09%09trackName =
@@ -1401,175 +1401,99 @@
 %09%09%09e
-rrorsDict%5BtrackName%5D = error%0A%09%09if (re.search(r'Encountered', line) or re.search(r'md5 did not match decoded data, file is corrupt.', line)):%0A%09%09%09nbErrorsDbPowerAmp += 1
+lse:%0A%09%09%09%09nbErrorsDbPowerAmp += 1%0A%09%09%09errorsDict%5BtrackName%5D = error%0A%09%09%09print(trackName, line)
 %0A%0A%09e

Improve dbPowerAmp error report parsing