Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #import datetime
- import os
- import platform
- import glob
- from mutagen.mp3 import MP3
- from datetime import date
- # find out if we're running on Windows, Mac or Linux
- if platform.system()=="Windows":clsMode="cls"
- else:clsMode="clear" #Linux/Mac
- blnQuit=False
- strDirName="/run/media/zeb/2TB-SATA2/Work MP3/1980s/"
- strArtist="Alanis Morissette"
- strAlbum="!LEAVE"
- intYear=1995
- intMinYear=1500
- intMaxYear=date.today().year
- def cls():
- _=os.system(clsMode)
- def txtCentre(txt):
- rows,columns=os.popen('stty size','r').read().split()
- pos=int(columns)/2-(len(txt)/2)
- print(" "*int(pos),txt)
- def terminate(txt):
- print(txt)
- os._exit(os.EX_CONFIG)
- def pressReturn():
- _=input("\nPress RETURN to continue...")
- def init():
- rows,columns=os.popen('stty size','r').read().split()
- if int(rows)<20:terminate("ERROR: Console needs to be at least 20 lines high!")
- if int(columns)<80:terminate("ERROR: Console needs to be at least 80 lines high!")
- def title(txt):
- cls()
- print("MP3Tagger v1.oo (7th Nov 2022) by Zeb\n")
- print(txt.upper()+"\n"+"="*len(txt)+"\n")
- def setDir():
- global strDirName
- title("Set Directory")
- print(f"Current path : {strDirName}")
- tmp=input("Enter new path: ")
- if tmp!="":strDirName=tmp
- def setArtist():
- global strArtist
- title("Set Artist Name")
- print(f"Current name : {strArtist}")
- tmp=input("Enter new name: ")
- if tmp!="":strArtist=tmp
- def setAlbum():
- global strAlbum
- title("Set Artist Name")
- print(f"Current album title : {strAlbum}")
- tmp=input("Enter album title: ")
- if tmp!="":strAlbum=tmp
- def setYear():
- global intYear,intMinYear,intMaxYear
- title("Set Year")
- print(f"Current year : {intYear}")
- tmp=input("Enter new year: ")
- if len(tmp)>0:
- if int(tmp)>intMinYear and int(tmp)<=intMaxYear:intYear=tmp
- def writeTags():
- title("Write Tags")
- print(f"Examining: {strDirName}")
- 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.")
- pressReturn()
- def menu():
- global blnQuit,intMaxYear
- while blnQuit==False:
- title("Main Menu")
- print(f"1. Set dir ({strDirName})");
- print(f"2. Set artist ({strArtist})");
- print(f"3. Set album ({strAlbum})");
- print(f"4. Set year ({intYear})");
- print("5. Write tags")
- print("6. Quit")
- print("")
- strOpt=input("Enter an option: ")
- if strOpt=="1":setDir()
- elif strOpt=="2":setArtist()
- elif strOpt=="3":setAlbum()
- elif strOpt=="4":setYear()
- elif strOpt=="5":writeTags()
- elif strOpt=="6":blnQuit=True
- init()
- menu()
- cls()
- print("Goodbye.")
- #x=datetime.datetime.now()
- #print(x.strftime("%d-%b-%Y %H:%M:%S (Week %W)"))
Add Comment
Please, Sign In to add comment