wes321

Plex Script to Remove Original Files

May 18th, 2016
1,940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. #! python
  2. import os
  3.  
  4. # This script checks you have a mp4 file in the Plex Versions/Original Quality folder. If you do it moves the other version in that directory.
  5. # Make sure to drop this file in the directory with all your folders of movies and then run python filename.py in terminal from that directory
  6.  
  7. maxAmount = 1 # Set this for how many you want to move over
  8. archiveDir = '_todelete/' # Set this to the directoy name you want the files moved to
  9. checkDir = "Original Quality" # I use original quality for the converted files. If you use another type put the directory name from Plex Versions/ in here
  10. directorySplit = '/' # For running on Windows filesystem
  11.  
  12. i = 0
  13. def currentFiles(path):
  14.     global i, maxAmount, archiveDir, directorySplit
  15.     for root, dirs, files in os.walk(str(path)):
  16.         path1 = root.split(directorySplit)
  17.         for file in files:
  18.             if "Original Quality" not in path1 and (".mp4" in file or ".mkv" in file or ".m4v" in file or ".avi" in file or ".wmv" in file):
  19.                 filepath = directorySplit.join(path1)+file
  20.                 if not os.path.exists(archiveDir):
  21.                     os.makedirs(archiveDir)
  22.                 print ("Moved "+filepath+"  -->  "+archiveDir+file) #if Python 3
  23.                 #print "Moved "+filepath+"  -->  "+archiveDir+file #if Python 2
  24.  
  25.                 if os.path.exists(filepath):
  26.                     os.rename(filepath, archiveDir+file)
  27.                     i = i + 1
  28.  
  29. def runCheck():
  30.     global archiveDir, checkDir, maxAmount, i, directorySplit
  31.     for root, dirs, files in os.walk("."):
  32.         path = root.split(directorySplit)
  33.         for file in files:
  34.             if checkDir in path and ".mp4" in file:
  35.                 if i < maxAmount:
  36.                     currentFiles(str(path[0]+directorySplit+path[1]+directorySplit))
  37.                 else:
  38.                     return
  39.     return
  40.  
  41. runCheck()
Advertisement
Add Comment
Please, Sign In to add comment