Skip to content

Instantly share code, notes, and snippets.

@dannyshisler
Created January 21, 2019 16:31
Show Gist options
  • Select an option

  • Save dannyshisler/f9711bd6b46d6dbf2f340216318820bc to your computer and use it in GitHub Desktop.

Select an option

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
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