Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # MP3Tagger v1.00 (7th Nov 2022)
- # Written by Zeb
- import glob
- from mutagen.mp3 import MP3
- from mutagen.easyid3 import EasyID3
- from mutagen.id3 import ID3, TIT2, TIT3, TALB, TPE1, TRCK, TYER
- from tkinter import *
- from tkinter import ttk
- from tkinter import messagebox
- from tkinter import filedialog as fd
- #from tkinter import tkFileDialog
- intWinWidth=400
- intWinHeight=200
- strDirName="/run/media/zeb/1TB-SATA4/Music/TEST"
- strArtist="Alanis Morissette"
- strAlbum="!CLR"
- intYear=1995
- def checkQuit():
- opt=messagebox.askyesno(message='Are you sure you want to quit?',icon='question',title='Quit')
- if opt:win.destroy()
- def actionSelectDirectory():
- txt=varDirName.get()
- win.directory=fd.askdirectory()
- varDirName.set(win.directory)
- def actionStart():
- strDirName=varDirName.get()
- strArtistName=varArtist.get()
- strAlbumName=varAlbum.get()
- intYear=int(varYear.get())
- print(f"Examining: {strDirName}")
- print(f"Artist: {strArtistName}")
- print(f"Album : {strAlbumName}")
- print(f"Year : {intYear}\n")
- lstFiles=glob.glob(strDirName+"/*.mp3")
- lstFiles.sort()
- # for i in lstFiles:
- # print(i.removeprefix(strDirName))
- if len(lstFiles)>0:print("Found:","{:,}".format(len(lstFiles)))
- else:print("No MP3 files were found.")
- for i in lstFiles:
- tmp=i.removeprefix(strDirName+"/")
- tmp=tmp.removesuffix(".mp3")
- tmp=tmp.split(" - ")
- print(f"Processing: {tmp}");
- mp3file=MP3(i,ID3=EasyID3)
- print(mp3file)
- mp3file['artist']=tmp[0]
- mp3file['title']=tmp[1]
- mp3file['year']=str(intYear)
- mp3file.save()
- def centreButton(intBtnW,intWinW):
- return int(intWinW/2-intBtnW/2)
- win=Tk()
- #centre the window on the screen
- intWidth=win.winfo_screenwidth()
- if intWidth>1940:intWidth=intWidth/4 #have to divide by 4 due to dual monitor
- else:intWidth=intWidth/2
- intHeight=win.winfo_screenheight()/2
- intPosX=int(intWidth-intWinWidth/2)
- intPosY=int(intHeight-intWinHeight/2)
- #print(win.winfo_screen())
- win.geometry(str(intWinWidth)+"x"+str(intWinHeight)+"+"+str(intPosX)+"+"+str(intPosY))
- win.resizable(FALSE,FALSE)
- win.title('MP3Tagger v1.oo (7th Nov 2022) by Zeb')
- win.protocol("WM_DELETE_WINDOW",checkQuit)
- lblDirName=ttk.Label(win,text='Dir Path:').place(x=10,y=10)
- varDirName=StringVar()
- varDirName.set(strDirName)
- btnDirName=ttk.Entry(win,textvariable=varDirName).place(x=90,y=10,width=270)
- ttk.Button(win,text="",command=actionSelectDirectory).place(x=370,y=10,width=20,height=20)
- lblArtist=ttk.Label(win,text='Artist Name:').place(x=10,y=40)
- varArtist=StringVar()
- varArtist.set(strArtist)
- btnArtist=ttk.Entry(win,textvariable=varArtist).place(x=90,y=40,width=300)
- lblAlbum=ttk.Label(win,text='Album Title:').place(x=10,y=70)
- varAlbum=StringVar()
- varAlbum.set(strAlbum)
- btnAlbum=ttk.Entry(win,textvariable=varAlbum).place(x=90,y=70,width=300)
- lblYear=ttk.Label(win,text='Year:').place(x=10,y=100)
- varYear=StringVar()
- varYear.set(str(intYear))
- btnYear=ttk.Entry(win,textvariable=varYear).place(x=90,y=100,width=300)
- ttk.Button(win,text="Start",command=actionStart).place(x=centreButton(50,intWinWidth),y=130,width=50,height=25)
- win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement