Skip to content

Instantly share code, notes, and snippets.

@luckytuvshee
Created March 5, 2020 09:47
Show Gist options
  • Save luckytuvshee/465b42707497a150f62b5304fc6a3751 to your computer and use it in GitHub Desktop.
Save luckytuvshee/465b42707497a150f62b5304fc6a3751 to your computer and use it in GitHub Desktop.
Automated music metadata changer, using eyeD3
import eyed3
import os
def readDir():
album_dirs = [x for x in os.listdir() if os.path.isdir(x)]
for dir in album_dirs:
print(os.getcwd())
for song in os.listdir(dir):
songPath = "{}/{}".format(os.getcwd(), dir)
changeMusicTag(songPath, song) # for single tracks
# changeAlbumTag(songPath, song) # for album tracks
def changeMusicTag(path, name):
aud = eyed3.load(path + "/" + name)
# remove .mp3 ext
name = name[:len(name) - 4]
tags = name.split('-')
print("Title:", tags[1])
print("Artist:", tags[0])
aud.initTag()
aud.tag.artist = tags[0]
aud.tag.title = tags[1]
aud.tag.save()
def changeAlbumTag(path, name):
aud = eyed3.load(path + "/" + name)
# remove .mp3 ext
name = name[:len(name) - 4]
tags = name.split('-')
print(tags)
album = tags[0].strip()
albumArtist = tags[2].strip()
title = name.strip()
featuredArtist = "".join(tags[3].split('ft. ')[1:])
if(len(featuredArtist) > 0):
artist = albumArtist + " ft. " + featuredArtist
else:
artist = albumArtist
# print("Album:", album)
# print("Track:", track)
# print("Album Artist:", albumArtist)
# print("Title:", title)
# print("Artist:", artist)
aud.initTag()
aud.tag.album = album
aud.tag.artist = artist
aud.tag.album_artist = albumArtist
aud.tag.title = title
aud.tag.save()
if __name__ == "__main__":
readDir()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment