Advertisement
Yesideez

SortHashZ.py

Nov 15th, 2022
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import glob
  4. import os
  5. import sys
  6.  
  7. strPattern="[#Z Karaoke]"
  8.  
  9. def rename(path,txt):
  10.   txtSource=path+"/"+txt+' [Z# Karaoke].cdg'
  11.   txtTarget=path+"/"+txt+' [Z Karaoke].cdg'
  12.   if os.path.exists(txtSource):
  13.     os.rename(txtSource,txtTarget)
  14.   else:
  15.     print("ERROR: Unable to rename",txtSource,"to",txtTarget)
  16. #  print("RENAME",txtSource,"TO",txtTarget)
  17.   txtSource=path+"/"+txt+' [Z# Karaoke].mp3'
  18.   txtTarget=path+"/"+txt+' [Z Karaoke].mp3'
  19.   if os.path.exists(txtSource):
  20.     os.rename(txtSource,txtTarget)
  21.   else:
  22.     print("ERROR: Unable to rename",txtSource,"to",txtTarget)
  23. #  print("RENAME",txtSource,"TO",txtTarget)
  24.  
  25. def delete(path,txt):
  26.   txtSource=txt+' [Z# Karaoke].cdg'
  27. #  print("RENAME",path+"/"+txtSource,"TO "+path+"/"+"DELETE_"+txtSource)
  28.   if os.path.exists(txtSource):
  29.     os.remove(txtSource)
  30.   else:
  31.     print("ERROR: Unable to rename",txtSource,"for deletion")
  32.   txtSource=txt+' [Z# Karaoke].mp3'
  33. #  print("RENAME",path+"/"+txtSource,"TO "+path+"/"+"DELETE_"+txtSource)
  34.   if os.path.exists(txtSource):
  35.     os.remove(txtSource)
  36.   else:
  37.     print("ERROR: Unable to rename",txtSource,"for deletion")
  38.  
  39. #print("Arguments:",len(sys.argv))
  40. #print(str(sys.argv))
  41. strPath=sys.argv[1]
  42. if os.path.exists(strPath):
  43.   lstFiles=glob.glob(strPath+"/*.cdg")
  44.   lstFiles.sort()
  45.   if len(lstFiles)>0:
  46.     print("Processing",len(lstFiles)*2,"files...")
  47. #    print(lstFiles)
  48.     for i in lstFiles:
  49.       intRenCount=0
  50.       intDelCount=0
  51.       tmp=i.removeprefix(sys.argv[1]+"/")
  52.       if "[#z karaoke]" in tmp.lower():
  53.         lst=tmp.split(" [",2)
  54.         lst[1]="["+lst[1]
  55. #        print()
  56.         found=False
  57.         for t in lstFiles:
  58. #          print("LOOKING FOR",lst[0].lower(),"-->",t.lower(),"***AND*** [z karaoke] --> ",t.lower())
  59.           if lst[0].lower() in t.lower() and "[z karaoke]" in t.lower():
  60.             found=True
  61.         if found:
  62.           delete(strPath,lst[0])
  63.           intDelCount+=1
  64.         else:
  65.           rename(strPath,lst[0])
  66.           intRenCount+=1
  67.   else:
  68.     print("ERROR: Unable to find any crg files")
  69. else:
  70.   print("ERROR: Directory doesn't exist")
  71.  
  72. if os.path.exists("D/Test.txt"):
  73.   os.rename("D/Test.txt","D/test.txt")
  74. else:
  75.   print("Failed")
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement