Exemple #1
0
 def parseNonOpus(self, parsedObject):
     from music21 import metadata
     try:
         corpusPath = metadata.MetadataBundle.corpusPathToKey(
             self.cleanFilePath)
         if parsedObject.metadata is not None:
             richMetadata = metadata.RichMetadata()
             richMetadata.merge(parsedObject.metadata)
             richMetadata.update(parsedObject)  # update based on Stream
             environLocal.printDebug(
                 'updateMetadataCache: storing: {0}'.format(corpusPath))
             metadataEntry = metadata.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 metadataPayload=richMetadata,
             )
             self.results.append(metadataEntry)
         else:
             environLocal.printDebug(
                 'addFromPaths: got stream without metadata, '
                 'creating stub: {0}'.format(
                     common.relativepath(self.cleanFilePath)))
             metadataEntry = metadata.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 metadataPayload=None,
             )
             self.results.append(metadataEntry)
     except Exception:  # wide catch is fine. pylint: disable=broad-except
         environLocal.warn('Had a problem with extracting metadata '
                           'for {0}, piece ignored'.format(self.filePath))
         environLocal.printDebug(traceback.format_exc())
Exemple #2
0
 def parseOpusScore(self, score, scoreNumber):
     # scoreNumber is a zeroIndexed value.
     # score.metadata.number is the retrieval code; which is
     # probably 1 indexed, and might have gaps
     from music21 import metadata
     try:
         # updgrade metadata to richMetadata
         richMetadata = metadata.RichMetadata()
         richMetadata.merge(score.metadata)
         richMetadata.update(score)  # update based on Stream
         if score.metadata is None or score.metadata.number is None:
             environLocal.printDebug(
                 'addFromPaths: got Opus that contains '
                 'Streams that do not have work numbers: '
                 '{0}'.format(self.filePath))
         else:
             # update path to include work number
             corpusPath = metadata.MetadataBundle.corpusPathToKey(
                 self.cleanFilePath,
                 number=score.metadata.number,
             )
             environLocal.printDebug(
                 'addFromPaths: storing: {0}'.format(corpusPath))
             metadataEntry = metadata.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 number=score.metadata.number,
                 metadataPayload=richMetadata,
             )
             self.results.append(metadataEntry)
     except Exception as exception:  # pylint: disable=broad-except
         environLocal.warn('Had a problem with extracting metadata '
                           'for score {0} in {1}, whole opus ignored: '
                           '{2}'.format(scoreNumber, self.filePath,
                                        str(exception)))
         environLocal.printDebug(traceback.format_exc())
Exemple #3
0
 def parseOpus(self, parsedObject):
     from music21 import metadata
     # need to get scores from each opus?
     # problem here is that each sub-work has metadata, but there
     # is only a single source file
     try:
         for scoreNumber, score in enumerate(parsedObject.scores):
             self.parseOpusScore(score, scoreNumber)
             del score  # for memory conservation
     except Exception as exception:  # wide catch is fine. pylint: disable=broad-except
         environLocal.warn(
             'Had a problem with extracting metadata for score {0} '
             'in {1}, whole opus ignored: {2}'.format(
                 scoreNumber, self.filePath, str(exception)))
         environLocal.printDebug(traceback.format_exc())
     # Create a dummy metadata entry, representing the entire opus.
     # This lets the metadata bundle know it has already processed this
     # entire opus on the next cache update.
     metadataEntry = metadata.MetadataEntry(
         sourcePath=self.cleanFilePath,
         metadataPayload=None,
     )
     self.results.append(metadataEntry)