Created
January 21, 2019 16:31
-
-
Save dannyshisler/f9711bd6b46d6dbf2f340216318820bc to your computer and use it in GitHub Desktop.
Python 3.7 script for reading a batch of mp3 files and extracting their coverart to image files and their metadata to a csv file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import eyed3 | |
| import os | |
| import csv | |
| def main(): | |
| folder = "/Users/danny/mymp3folder/" | |
| with open(f'{folder}tracks_metadata.csv', mode='w') as track_file: | |
| track_writer = csv.writer(track_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) | |
| track_writer.writerow(['file', 'artist', 'track', 'album', 'genre']) | |
| for file in os.listdir(folder): | |
| if file.endswith(".mp3"): | |
| print(file) | |
| audiofile = eyed3.load(f"{folder}{file}") | |
| image_data = bytes(audiofile.tag.images[0].image_data) | |
| f = open(f'{folder}{file}.jpg', 'wb') | |
| f.write(image_data) | |
| f.close() | |
| print("\t", str(audiofile.tag.artist), str(audiofile.tag.title), str(audiofile.tag.album), str(audiofile.tag.genre)) | |
| track_writer.writerow([file, str(audiofile.tag.artist), str(audiofile.tag.title), str(audiofile.tag.album), str(audiofile.tag.genre)]) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment