Advertisement
Yesideez

Untitled

Nov 8th, 2022
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. #import datetime
  4. import os
  5. import platform
  6. import glob
  7. from mutagen.mp3 import MP3
  8. from datetime import date
  9.  
  10. # find out if we're running on Windows, Mac or Linux
  11. if platform.system()=="Windows":clsMode="cls"
  12. else:clsMode="clear" #Linux/Mac
  13.  
  14. blnQuit=False
  15. strDirName="/run/media/zeb/2TB-SATA2/Work MP3/1980s/"
  16. strArtist="Alanis Morissette"
  17. strAlbum="!LEAVE"
  18. intYear=1995
  19. intMinYear=1500
  20. intMaxYear=date.today().year
  21.  
  22. def cls():
  23.   _=os.system(clsMode)
  24.  
  25. def txtCentre(txt):
  26.   rows,columns=os.popen('stty size','r').read().split()
  27.   pos=int(columns)/2-(len(txt)/2)
  28.   print(" "*int(pos),txt)
  29.  
  30. def terminate(txt):
  31.   print(txt)
  32.   os._exit(os.EX_CONFIG)
  33.  
  34. def pressReturn():
  35.   _=input("\nPress RETURN to continue...")
  36.  
  37. def init():
  38.   rows,columns=os.popen('stty size','r').read().split()
  39.   if int(rows)<20:terminate("ERROR: Console needs to be at least 20 lines high!")
  40.   if int(columns)<80:terminate("ERROR: Console needs to be at least 80 lines high!")
  41.  
  42. def title(txt):
  43.   cls()
  44.   print("MP3Tagger v1.oo (7th Nov 2022) by Zeb\n")
  45.   print(txt.upper()+"\n"+"="*len(txt)+"\n")
  46.  
  47. def setDir():
  48.   global strDirName
  49.   title("Set Directory")
  50.   print(f"Current path  : {strDirName}")
  51.   tmp=input("Enter new path: ")
  52.   if tmp!="":strDirName=tmp
  53.  
  54. def setArtist():
  55.   global strArtist
  56.   title("Set Artist Name")
  57.   print(f"Current name  : {strArtist}")
  58.   tmp=input("Enter new name: ")
  59.   if tmp!="":strArtist=tmp
  60.  
  61. def setAlbum():
  62.   global strAlbum
  63.   title("Set Artist Name")
  64.   print(f"Current album title  : {strAlbum}")
  65.   tmp=input("Enter album title: ")
  66.   if tmp!="":strAlbum=tmp
  67.  
  68. def setYear():
  69.   global intYear,intMinYear,intMaxYear
  70.   title("Set Year")
  71.   print(f"Current year  : {intYear}")
  72.   tmp=input("Enter new year: ")
  73.   if len(tmp)>0:
  74.     if int(tmp)>intMinYear and int(tmp)<=intMaxYear:intYear=tmp
  75.  
  76. def writeTags():
  77.   title("Write Tags")
  78.   print(f"Examining: {strDirName}")
  79.   lstFiles=glob.glob(strDirName+"*.mp3")
  80.   lstFiles.sort()
  81. #  for i in lstFiles:
  82. #    print(i.removeprefix(strDirName))
  83.   if len(lstFiles)>0:print("Found:","{:,}".format(len(lstFiles)))
  84.   else:print("No MP3 files were found.")
  85.   pressReturn()
  86.  
  87. def menu():
  88.   global blnQuit,intMaxYear
  89.   while blnQuit==False:
  90.     title("Main Menu")
  91.     print(f"1. Set dir ({strDirName})");
  92.     print(f"2. Set artist ({strArtist})");
  93.     print(f"3. Set album ({strAlbum})");
  94.     print(f"4. Set year ({intYear})");
  95.     print("5. Write tags")
  96.     print("6. Quit")
  97.     print("")
  98.     strOpt=input("Enter an option: ")
  99.     if strOpt=="1":setDir()
  100.     elif strOpt=="2":setArtist()
  101.     elif strOpt=="3":setAlbum()
  102.     elif strOpt=="4":setYear()
  103.     elif strOpt=="5":writeTags()
  104.     elif strOpt=="6":blnQuit=True
  105.  
  106. init()
  107. menu()
  108. cls()
  109. print("Goodbye.")
  110.  
  111. #x=datetime.datetime.now()
  112. #print(x.strftime("%d-%b-%Y %H:%M:%S (Week %W)"))
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement