Пример #1
0
 def testJimmy(self):
     jimmy = createAudioFile(testDir + "/data/J/Jimmy Eat World/Bleed American/Jimmy Eat World - The Middle.mp3")
     jimmy.readFile()
     self.assertEqual(jimmy.id3v2version, "ID3v2.3.0")
     self.assertTrue(not jimmy.unsynchronization, "Unsynchronization flag is set")
Пример #2
0
    def __init__(self, library, subdir = ".", artistRe = None, albumRe = None, titleRe = None):
        self.files        = {}    # Songs indexed by filename
        self.audioMd5s    = {}    # Songs indexed by MD5
        self.sizes        = {}    # Lists of songs, indexed by size (only until audio MD5s are generated)
        self.artists      = {}
        self.artistMaxLen = len("Artist or Group")
        self.albumMaxLen  = len("Album")
        self.titleMaxLen  = len("Song")
        self.library      = os.path.abspath(library)    # Pass this single reference to all songs to conserve memory

        curDir = os.getcwd()
        os.chdir(library)    # Keep paths short

        for dirPath, subDirs, dirFiles in os.walk(subdir):
            for file in dirFiles:
                filePath  = dirPath + "/" + file

                try:
                    audioFile = createAudioFile(filePath, rootPath=library)

                    if not audioFile:
                        continue

                    key           = file.lower()    # The lower case file name must be a unique key in the library
                    audioFile.key = key

                    # Only check like sized files for dups while constructing if run in 'fix' mode (slows loading a lot)
                    #
                    if options['fix']:
                        other         = self.findSong(audioFile)

                        if other:
                            warn("Ignoring file %s because its audio is identical to %s" % (filePath, other.filePath))
                            continue

                    if key in self.files:
                        warn("Ignoring file %s because it's name duplicates %s" % (filePath, self.files[key].filePath))
                        continue

                    self.files[key]  = audioFile
                    size             = audioFile.getSize()
                    self.sizes[size] = self.sizes[size] if size in self.sizes else []
                    self.sizes[size].append(audioFile)

                    #print filePath

                    artist = audioFile.artist if audioFile.artist else "Unknown"
                    album  = audioFile.album  if audioFile.album  else "Unknown"
                    title  = audioFile.title

                    if artist not in self.artists:
                        self.artists[artist] = {'artist': audioFile.artist, 'albums': {}}
                        self.artistMaxLen    = max(self.artistMaxLen, len(audioFile.artist))

                    if album not in self.artists[artist]['albums']:
                        self.artists[artist]['albums'][album] = {'album': audioFile.album, 'songs': {}}
                        self.albumMaxLen                      = max(self.albumMaxLen, len(audioFile.album))

                    if title not in self.artists[artist]['albums'][album]['songs']:
                        self.artists[artist]['albums'][album]['songs'][title] = audioFile
                        self.titleMaxLen                                      = max(self.titleMaxLen, len(audioFile.title))

                except Mp3FileError as error:
                    warn("Skipping invalid MP3 file (error %s)" % str(error), filePath)
                    continue

        os.chdir(curDir)    # Restore the path for the caller
Пример #3
0
 def testAlice(self):
     alice = createAudioFile(testDir + "/data/A/Alice In Chains/Alice in Chains - Them Bones.mp3")
     alice.readFile()
     self.assertEqual(alice.id3v2version, "ID3v2.3.0")
     self.assertTrue(not alice.unsynchronization, "Unsynchronization flag is set")