Extra check for supported inputs

Added input for rawtxt (speedy input, but with assumptions, so it has to be generated by this program
Fix check for selected input extensions
This commit is contained in:
Marco van Dijk 2021-07-09 21:46:29 +02:00
parent 6187d6e123
commit e32d66c10b
3 changed files with 62 additions and 4 deletions

View File

@ -409,7 +409,61 @@ class Song:
@return None @return None
""" """
def initPreprocessed(self): def initPreprocessed(self):
pass # Get raw data
self.rawData = readSourceFile(self.inputFile)
parseData = self.rawData
# While not EOF: build sections untill new section found.
delimiterIndex = parseData.find("[")
if delimiterIndex == -1:
print("Cannot parse input file, since it is not delimited by '[<sectionName>]' entries")
return
# Start with metadata
self.metadata = parseData[:delimiterIndex]
print("Set '{}' as metadata".format(self.metadata))
parseData = parseData[delimiterIndex:]
# We are now at the start of the first section, at the '[' character
lines = parseData.splitlines(True)
if not len(lines):
return
#print("We found {} lines of data".format(len(lines)))
# Init first section by popping the delimiter
thisSection = Section()
thisSection.header = lines.pop(0)
# First line is always tab->lyric
isTabLine = True
print("First header is '{}'".format(thisSection.header))
for line in lines:
# If it is a [header], it is a new section
if line[0] == '[':
# Store prev section
thisSection.initSections()
if thisSection.isParsed:
self.sections.append(thisSection)
else:
print("Aborting parse due to section not being parseable.")
return
# Reset, new section
thisSection = Section()
thisSection.header = line
#print("Header is '{}'".format(thisSection.header))
isTabLine = True
# Else is has lines in order tabline->lyricline->repeat
elif isTabLine:
#print("Adding Tabline is '{}'".format(line))
thisSection.tablatures.append(line)
isTabLine = False
else:
#print("Adding Lyricline is '{}'".format(line))
thisSection.lyrics.append(line)
isTabLine = True
# Add final section data
thisSection.initSections()
if thisSection.isParsed:
self.sections.append(thisSection)
else:
print("Aborting parse due to section not being parseable.")
return
self.isParsed = True
"""!@brief Parses self.rawData into Section objects and metadata """!@brief Parses self.rawData into Section objects and metadata
@return None @return None

View File

@ -72,7 +72,7 @@ def getSongObjects():
# get all files we can find, then filter on supported extensions # get all files we can find, then filter on supported extensions
for inputFolder in configObj['inputfolders'].split(','): for inputFolder in configObj['inputfolders'].split(','):
for filePath in walkDirectory(inputFolder, recursionDepth): for filePath in walkDirectory(inputFolder, recursionDepth):
if ((filePath[filePath.find('.'):] == ".txt" ) and configObj['readtxt']) or ((filePath[filePath.find('.'):] == ".rawtxt" ) and configObj['readraw']): if ((filePath[filePath.find('.'):] == ".txt" ) and configObj['readtxt'] == '1') or ((filePath[filePath.find('.'):] == ".rawtxt" ) and configObj['readraw'] == '1'):
#print("Found supported file '{}'".format(filePath)) #print("Found supported file '{}'".format(filePath))
txtFileLocations.append(filePath) txtFileLocations.append(filePath)
#else: #else:

View File

@ -43,10 +43,14 @@ def main():
for song in songs: for song in songs:
print("Start parsing of file '{}'...".format(song.inputFile)) print("Start parsing of file '{}'...".format(song.inputFile))
# Initialise internal data structures # Initialise internal data structures
print("song file extension {}".format(song.fileExtension))
if song.fileExtension == 'txt': if song.fileExtension == 'txt':
song.initSections() song.initSections()
elif song.fileExtension == 'raw': elif song.fileExtension == 'rawtxt':
pass#song.initPreprocessed() song.initPreprocessed()
else:
print("File extension '{}' not supported. Skipping...".format(song.fileExtension))
continue
# If input is .raw output. If output to raw is set, overwrite itself # If input is .raw output. If output to raw is set, overwrite itself
# ready quickly using rules # ready quickly using rules
if not song.isParsed: if not song.isParsed: