mirror of
https://github.com/stronk-dev/Guitar-Sheet-Parser.git
synced 2025-07-05 08:25:09 +02:00
Added abilit to write header file containing info on what lines contain what kind of data in .txt and .rawtxt output
This commit is contained in:
parent
15400a037f
commit
50e1fe05c0
@ -52,7 +52,8 @@ def initConfig():
|
|||||||
'tryToShrinkRatio' : 0.25,
|
'tryToShrinkRatio' : 0.25,
|
||||||
'lowestwhitespaceonwidthratioallowed': 0.90,
|
'lowestwhitespaceonwidthratioallowed': 0.90,
|
||||||
'hightestwhitespaceonwidthratioallowed': 0.40,
|
'hightestwhitespaceonwidthratioallowed': 0.40,
|
||||||
'keepEmptyLines': 1
|
'keepEmptyLines': 1,
|
||||||
|
'writeMetaData': 0
|
||||||
}
|
}
|
||||||
# (if CMD arguments: load CMD arguments to override specific settings)
|
# (if CMD arguments: load CMD arguments to override specific settings)
|
||||||
with open('config.ini', 'w') as configfile:
|
with open('config.ini', 'w') as configfile:
|
||||||
|
@ -235,6 +235,8 @@ class Song:
|
|||||||
self.hightestWhitespaceOnWidthRatioAllowed = float(configObj['hightestWhitespaceOnWidthRatioAllowed'])
|
self.hightestWhitespaceOnWidthRatioAllowed = float(configObj['hightestWhitespaceOnWidthRatioAllowed'])
|
||||||
# Strip empty lines from input or keep em
|
# Strip empty lines from input or keep em
|
||||||
self.keepEmptyLines = configObj['keepEmptyLines'] == '1'
|
self.keepEmptyLines = configObj['keepEmptyLines'] == '1'
|
||||||
|
# Strip empty lines from input or keep em
|
||||||
|
self.writeMetadata = configObj['writemetadata'] == '1'
|
||||||
|
|
||||||
|
|
||||||
"""!@brief Calculates dimensions of metadata
|
"""!@brief Calculates dimensions of metadata
|
||||||
|
@ -39,6 +39,13 @@ def outputToTxt(folderLocation, printRaw, songObj):
|
|||||||
#print("Directory " , folderLocation , " already exists")
|
#print("Directory " , folderLocation , " already exists")
|
||||||
|
|
||||||
output = ""
|
output = ""
|
||||||
|
emptyLines = []
|
||||||
|
lyricLines = []
|
||||||
|
nonLyricLines = []
|
||||||
|
sectionHeaders = []
|
||||||
|
metadataLines = []
|
||||||
|
|
||||||
|
lineCounter = 0
|
||||||
# Write metadata
|
# Write metadata
|
||||||
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
|
||||||
@ -47,9 +54,14 @@ def outputToTxt(folderLocation, printRaw, songObj):
|
|||||||
continue
|
continue
|
||||||
#print("meta line '{}'".format(line))
|
#print("meta line '{}'".format(line))
|
||||||
output += line + '\r\n'
|
output += line + '\r\n'
|
||||||
|
metadataLines.append(lineCounter)
|
||||||
|
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:
|
if not printRaw:
|
||||||
output += '\r\n'
|
output += '\r\n'
|
||||||
|
emptyLines.append(lineCounter)
|
||||||
|
lineCounter += 1
|
||||||
# Draw all pages
|
# Draw all pages
|
||||||
for section in songObj.sections:
|
for section in songObj.sections:
|
||||||
lineIterator = 0
|
lineIterator = 0
|
||||||
@ -59,32 +71,89 @@ def outputToTxt(folderLocation, printRaw, songObj):
|
|||||||
return
|
return
|
||||||
# write section title
|
# write section title
|
||||||
output += section.header.rstrip() + '\r\n'
|
output += section.header.rstrip() + '\r\n'
|
||||||
|
sectionHeaders.append(lineCounter)
|
||||||
|
lineCounter += 1
|
||||||
# Write each line tablature&lyric data
|
# Write each line tablature&lyric data
|
||||||
while lineIterator < amountOfLines:
|
while lineIterator < amountOfLines:
|
||||||
tabline = section.tablatures[lineIterator].rstrip()
|
tabline = section.tablatures[lineIterator].rstrip()
|
||||||
lyricline = section.lyrics[lineIterator].rstrip()
|
lyricline = section.lyrics[lineIterator].rstrip()
|
||||||
if printRaw or len(tabline):
|
if printRaw or len(tabline):
|
||||||
output += tabline + '\r\n'
|
output += tabline + '\r\n'
|
||||||
|
nonLyricLines.append(lineCounter)
|
||||||
|
lineCounter += 1
|
||||||
if printRaw or len(lyricline):
|
if printRaw or len(lyricline):
|
||||||
output += lyricline + '\r\n'
|
output += lyricline + '\r\n'
|
||||||
|
lyricLines.append(lineCounter)
|
||||||
|
lineCounter += 1
|
||||||
#If both lines are empty, it is an empty line
|
#If both lines are empty, it is an empty line
|
||||||
# So if printRaw == false, insert one empty line
|
# 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)
|
||||||
|
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:
|
if not printRaw:
|
||||||
output += '\r\n'
|
output += '\r\n'
|
||||||
|
emptyLines.append(lineCounter)
|
||||||
|
lineCounter += 1
|
||||||
# Finished, so print some trailing endlines
|
# Finished, so print some trailing endlines
|
||||||
outputLocation = ""
|
outputLocation = ""
|
||||||
if not printRaw:
|
if not printRaw:
|
||||||
output += '\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n'
|
|
||||||
outputLocation = folderLocation + "/" + songObj.title + ".txt"
|
outputLocation = folderLocation + "/" + songObj.title + ".txt"
|
||||||
else:
|
else:
|
||||||
outputLocation = folderLocation + "/" + songObj.title + ".rawtxt"
|
outputLocation = folderLocation + "/" + songObj.title + ".rawtxt"
|
||||||
with open(outputLocation, "w") as fileOut:
|
with open(outputLocation, "w") as fileOut:
|
||||||
fileOut.write(output)
|
fileOut.write(output)
|
||||||
|
if songObj.writeMetadata:
|
||||||
|
if printRaw:
|
||||||
|
outputLocation = folderLocation + "/" + songObj.title + ".rawtxt.json"
|
||||||
|
else:
|
||||||
|
outputLocation = folderLocation + "/" + songObj.title + ".txt.json"
|
||||||
|
|
||||||
|
with open(outputLocation, "w") as fileOut:
|
||||||
|
fileOut.write('{\r\n')
|
||||||
|
fileOut.write(' "emptyLines": [')
|
||||||
|
hasNext = len(emptyLines)
|
||||||
|
for entry in emptyLines:
|
||||||
|
hasNext -= 1
|
||||||
|
fileOut.write(str(entry))
|
||||||
|
if hasNext:
|
||||||
|
fileOut.write(', ')
|
||||||
|
fileOut.write('],\r\n')
|
||||||
|
fileOut.write(' "lyricLines": [')
|
||||||
|
hasNext = len(lyricLines)
|
||||||
|
for entry in lyricLines:
|
||||||
|
hasNext -= 1
|
||||||
|
fileOut.write(str(entry))
|
||||||
|
if hasNext:
|
||||||
|
fileOut.write(', ')
|
||||||
|
fileOut.write('],\r\n')
|
||||||
|
fileOut.write(' "nonLyricLines": [')
|
||||||
|
hasNext = len(nonLyricLines)
|
||||||
|
for entry in nonLyricLines:
|
||||||
|
hasNext -= 1
|
||||||
|
fileOut.write(str(entry))
|
||||||
|
if hasNext:
|
||||||
|
fileOut.write(', ')
|
||||||
|
fileOut.write('],\r\n')
|
||||||
|
fileOut.write(' "sectionHeaders": [')
|
||||||
|
hasNext = len(sectionHeaders)
|
||||||
|
for entry in sectionHeaders:
|
||||||
|
hasNext -= 1
|
||||||
|
fileOut.write(str(entry))
|
||||||
|
if hasNext:
|
||||||
|
fileOut.write(', ')
|
||||||
|
fileOut.write('],\r\n')
|
||||||
|
fileOut.write(' "metadataLines": [')
|
||||||
|
hasNext = len(metadataLines)
|
||||||
|
for entry in metadataLines:
|
||||||
|
hasNext -= 1
|
||||||
|
fileOut.write(str(entry))
|
||||||
|
if hasNext:
|
||||||
|
fileOut.write(', ')
|
||||||
|
fileOut.write(']\r\n')
|
||||||
|
fileOut.write('}\r\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user