do not add extra whitespace if we already keep the whitespace from the input. This way, we can generate .txt files which should be identical to the input

This commit is contained in:
Marco van Dijk 2021-07-09 23:58:01 +02:00
parent f7ec726eae
commit a69606ee4c

View File

@ -50,7 +50,7 @@ def outputToTxt(folderLocation, printRaw, songObj):
for line in songObj.metadata.split('\n'): for line in songObj.metadata.split('\n'):
# remove any unwanted characters from metadata # remove any unwanted characters from metadata
line = line.rstrip() line = line.rstrip()
if not line: if not songObj.keepEmptyLines and not line:
continue continue
#print("meta line '{}'".format(line)) #print("meta line '{}'".format(line))
output += line + '\r\n' output += line + '\r\n'
@ -58,7 +58,8 @@ def outputToTxt(folderLocation, printRaw, songObj):
lineCounter += 1 lineCounter += 1
# If exporting raw, do not include the whitespace between metadata and sections # If exporting raw, do not include the whitespace between metadata and sections
if not printRaw: # also do not add an extra whitespace if we already keep whitespaces from input
if not printRaw and not songObj.keepEmptyLines:
output += '\r\n' output += '\r\n'
emptyLines.append(lineCounter) emptyLines.append(lineCounter)
lineCounter += 1 lineCounter += 1
@ -85,19 +86,19 @@ def outputToTxt(folderLocation, printRaw, songObj):
output += lyricline + '\r\n' output += lyricline + '\r\n'
lyricLines.append(lineCounter) lyricLines.append(lineCounter)
lineCounter += 1 lineCounter += 1
#If both lines are empty, it is an empty line #If both lines are empty, it is 1 emptyline
# So if printRaw == false, insert one empty line
if not printRaw and not len(tabline) and not len(lyricline): if not printRaw and not len(tabline) and not len(lyricline):
output += '\r\n' output += '\r\n'
emptyLines.append(lineCounter) emptyLines.append(lineCounter)
lineCounter += 1 lineCounter += 1
lineIterator += 1 lineIterator += 1
# If exporting raw, do not include the whitespace between sections # If exporting raw, do not include the whitespace between sections
if not printRaw: # also do not add an extra whitespace if we already keep whitespaces from input
if not printRaw and not songObj.keepEmptyLines:
output += '\r\n' output += '\r\n'
emptyLines.append(lineCounter) emptyLines.append(lineCounter)
lineCounter += 1 lineCounter += 1
# Finished, so print some trailing endlines # Finished
outputLocation = "" outputLocation = ""
if not printRaw: if not printRaw:
outputLocation = folderLocation + "/" + songObj.title + ".txt" outputLocation = folderLocation + "/" + songObj.title + ".txt"