Advertisement
Yesideez

MP3Tagger

Nov 8th, 2022
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # MP3Tagger v1.00 (7th Nov 2022)
  4. # Written by Zeb
  5.  
  6. import glob
  7. from mutagen.mp3 import MP3
  8. from mutagen.easyid3 import EasyID3
  9. from mutagen.id3 import ID3, TIT2, TIT3, TALB, TPE1, TRCK, TYER
  10. from tkinter import *
  11. from tkinter import ttk
  12. from tkinter import messagebox
  13. from tkinter import filedialog as fd
  14. #from tkinter import tkFileDialog
  15.  
  16. intWinWidth=400
  17. intWinHeight=200
  18. strDirName="/run/media/zeb/1TB-SATA4/Music/TEST"
  19. strArtist="Alanis Morissette"
  20. strAlbum="!CLR"
  21. intYear=1995
  22.  
  23. def checkQuit():
  24.   opt=messagebox.askyesno(message='Are you sure you want to quit?',icon='question',title='Quit')
  25.   if opt:win.destroy()
  26.  
  27. def actionSelectDirectory():
  28.   txt=varDirName.get()
  29.   win.directory=fd.askdirectory()
  30.   varDirName.set(win.directory)
  31.  
  32. def actionStart():
  33.   strDirName=varDirName.get()
  34.   strArtistName=varArtist.get()
  35.   strAlbumName=varAlbum.get()
  36.   intYear=int(varYear.get())
  37.   print(f"Examining: {strDirName}")
  38.   print(f"Artist: {strArtistName}")
  39.   print(f"Album : {strAlbumName}")
  40.   print(f"Year  : {intYear}\n")
  41.   lstFiles=glob.glob(strDirName+"/*.mp3")
  42.   lstFiles.sort()
  43. #  for i in lstFiles:
  44. #    print(i.removeprefix(strDirName))
  45.   if len(lstFiles)>0:print("Found:","{:,}".format(len(lstFiles)))
  46.   else:print("No MP3 files were found.")
  47.   for i in lstFiles:
  48.     tmp=i.removeprefix(strDirName+"/")
  49.     tmp=tmp.removesuffix(".mp3")
  50.     tmp=tmp.split(" - ")
  51.     print(f"Processing: {tmp}");
  52.     mp3file=MP3(i,ID3=EasyID3)
  53.     print(mp3file)
  54.     mp3file['artist']=tmp[0]
  55.     mp3file['title']=tmp[1]
  56.     mp3file['year']=str(intYear)
  57.     mp3file.save()
  58.  
  59. def centreButton(intBtnW,intWinW):
  60.   return int(intWinW/2-intBtnW/2)
  61.  
  62. win=Tk()
  63.  
  64. #centre the window on the screen
  65. intWidth=win.winfo_screenwidth()
  66. if intWidth>1940:intWidth=intWidth/4 #have to divide by 4 due to dual monitor
  67. else:intWidth=intWidth/2
  68.  
  69. intHeight=win.winfo_screenheight()/2
  70. intPosX=int(intWidth-intWinWidth/2)
  71. intPosY=int(intHeight-intWinHeight/2)
  72.  
  73. #print(win.winfo_screen())
  74. win.geometry(str(intWinWidth)+"x"+str(intWinHeight)+"+"+str(intPosX)+"+"+str(intPosY))
  75. win.resizable(FALSE,FALSE)
  76. win.title('MP3Tagger v1.oo (7th Nov 2022) by Zeb')
  77. win.protocol("WM_DELETE_WINDOW",checkQuit)
  78.  
  79. lblDirName=ttk.Label(win,text='Dir Path:').place(x=10,y=10)
  80. varDirName=StringVar()
  81. varDirName.set(strDirName)
  82. btnDirName=ttk.Entry(win,textvariable=varDirName).place(x=90,y=10,width=270)
  83. ttk.Button(win,text="",command=actionSelectDirectory).place(x=370,y=10,width=20,height=20)
  84.  
  85. lblArtist=ttk.Label(win,text='Artist Name:').place(x=10,y=40)
  86. varArtist=StringVar()
  87. varArtist.set(strArtist)
  88. btnArtist=ttk.Entry(win,textvariable=varArtist).place(x=90,y=40,width=300)
  89.  
  90. lblAlbum=ttk.Label(win,text='Album Title:').place(x=10,y=70)
  91. varAlbum=StringVar()
  92. varAlbum.set(strAlbum)
  93. btnAlbum=ttk.Entry(win,textvariable=varAlbum).place(x=90,y=70,width=300)
  94.  
  95. lblYear=ttk.Label(win,text='Year:').place(x=10,y=100)
  96. varYear=StringVar()
  97. varYear.set(str(intYear))
  98. btnYear=ttk.Entry(win,textvariable=varYear).place(x=90,y=100,width=300)
  99.  
  100. ttk.Button(win,text="Start",command=actionStart).place(x=centreButton(50,intWinWidth),y=130,width=50,height=25)
  101.  
  102. win.mainloop()
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement