예제 #1
0
if __name__ == "__main__":
    config = get_config()

    db = SqliteDatabase()
    path = "mp3/"

    # fingerprint all files in a directory

    for filename in os.listdir(path):
        if filename.endswith(".mp3"):
            reader = FileReader(path + filename)
            audio = reader.parse_audio()

            song = db.get_song_by_filehash(audio["file_hash"])
            song_id = db.add_song(filename, audio["file_hash"])

            msg = " * %s %s: %s" % (
                colored("id=%s", "white", attrs=["dark"]),  # id
                colored("channels=%d", "white", attrs=["dark"]),  # channels
                colored("%s", "white", attrs=["bold"]),  # filename
            )
            print(msg % (song_id, len(audio["channels"]), filename))

            if song:
                hash_count = db.get_song_hashes_count(song_id)

                if hash_count > 0:
                    msg = "   already exists (%d hashes), skip" % hash_count
                    print(colored(msg, "red"))
if __name__ == '__main__':
    config = get_config()

    db = SqliteDatabase()
    path = "mp3/"

    # fingerprint all files in a directory

    for filename in os.listdir(path):
        if filename.endswith(".mp3"):
            reader = FileReader(path + filename)
            audio = reader.parse_audio()

            song = db.get_song_by_filehash(audio['file_hash'])
            song_id = db.add_song(filename, audio['file_hash'])

            msg = ' * %s %s: %s' % (
                colored('id=%s', 'white', attrs=['dark']),  # id
                colored('channels=%d', 'white', attrs=['dark']),  # channels
                colored('%s', 'white', attrs=['bold'])  # filename
            )
            print(msg % (song_id, len(audio['channels']), filename))

            if song:
                hash_count = db.get_song_hashes_count(song_id)

                if hash_count > 0:
                    msg = '   already exists (%d hashes), skip' % hash_count
                    print(colored(msg, 'red'))
            audio = reader.parse_audio()
            # Metadata storage
            metadata = []
            a_tag = TinyTag.get(path + filename, image=True)
            image_data = a_tag.get_image()
            # pi = Image.open(io.BytesIO(image_data))  #for viewing image

            metadata.append(a_tag.artist)
            metadata.append(a_tag.albumartist)
            metadata.append(a_tag.genre)
            metadata.append(a_tag.album)
            metadata.append(a_tag.year)
            # db.store_metadata(metadata)

            song = db.get_song_by_filehash(audio['file_hash'])
            song_id = db.add_song(filename, audio['file_hash'], metadata, image_data)

            msg = ' * %s %s: %s' % (
                colored('id=%s', 'white', attrs=['dark']),  # id
                colored('channels=%d', 'white', attrs=['dark']),  # channels
                colored('%s', 'white', attrs=['bold'])  # filename
            )
            print(msg % (song_id, len(audio['channels']), filename))

            if song:
                hash_count = db.get_song_hashes_count(song_id)

                if hash_count > 0:
                    msg = '   already exists (%d hashes), skip' % hash_count
                    print(colored(msg, 'red'))