diff --git a/lib/dataStructures.py b/lib/dataStructures.py index 69200c3..5aa6247 100644 --- a/lib/dataStructures.py +++ b/lib/dataStructures.py @@ -409,7 +409,61 @@ class Song: @return None """ 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 '[]' 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 @return None diff --git a/lib/initSongs.py b/lib/initSongs.py index ce238d5..4c30194 100644 --- a/lib/initSongs.py +++ b/lib/initSongs.py @@ -72,7 +72,7 @@ def getSongObjects(): # get all files we can find, then filter on supported extensions for inputFolder in configObj['inputfolders'].split(','): 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)) txtFileLocations.append(filePath) #else: diff --git a/main.py b/main.py index 31eaba4..8b94e2e 100644 --- a/main.py +++ b/main.py @@ -43,10 +43,14 @@ def main(): for song in songs: print("Start parsing of file '{}'...".format(song.inputFile)) # Initialise internal data structures + print("song file extension {}".format(song.fileExtension)) if song.fileExtension == 'txt': song.initSections() - elif song.fileExtension == 'raw': - pass#song.initPreprocessed() + elif song.fileExtension == 'rawtxt': + 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 # ready quickly using rules if not song.isParsed: