Created
September 6, 2020 16:10
-
-
Save varlen/7e1d1f29b324165ba527845e7a2560a9 to your computer and use it in GitHub Desktop.
Adiciona tags ID3 a partir do nome do arquivo
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 glob, os, eyed3 | |
#Lendo o diretorio atual | |
caminho = os.getcwd() | |
#Gerando a lista de arquivos mp3 | |
playlist = glob.glob(caminho + "\\*.mp3") | |
print(str(len(playlist)) + " musicas encontradas.") | |
print(playlist) | |
for musica in playlist: | |
arquivo = eyed3.load(musica) #Criando o objeto de tag ID3 | |
x = os.path.splitext(musica) #Tuple com o caminho e a extensao | |
y = x[0].split('\\') #Tuple separado pelas barras | |
z = y[-1].split(' - ')#Tuple separado por - | |
artista = z[0] #Primeiro elemento do tuple -> Artista | |
faixa = z[1] #Idem, para faixa | |
diretorio = y[-2] #Nome da pasta | |
arquivo.tag.artist = unicode(artista) #Passando os elementos para o objeto de tag | |
arquivo.tag.title = unicode(faixa) | |
arquivo.tag.album = unicode(diretorio) #Nome da pasta como album | |
arquivo.tag.save() | |
print("Tag editado: " + artista + " - " + faixa) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment