2n2u

Untitled

May 3rd, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import sys
  2. import patoolib
  3. from os import listdir, remove
  4. from shutil import rmtree
  5. from os.path import isfile, join, isdir
  6. import re
  7.  
  8. use_argv = True
  9. main_download_dir = "D:/DownloadsCompleted/"
  10. if sys.platform() == 'win':
  11.     windows_compare = main_download_dir.replace("/", "\\\\")
  12.  
  13. def extract(path, deleteonly=True):
  14.     # Extract file
  15.  
  16.     onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
  17.     onlydirs = [f for f in listdir(path) if isdir(join(path, f))]
  18.  
  19.     if not deleteonly:
  20.         for f in onlyfiles:
  21.             if f.endswith(".rar"):
  22.                 rar = path + "/" + f
  23.                 patoolib.extract_archive(rar, outdir=path)
  24.     # Removal of unwanted files    
  25.     for item in onlydirs:
  26.         rmtree(path + "/" + item)
  27.     for item in onlyfiles:
  28.         if item.endswith(".mkv") == False:
  29.             remove(path + "/" + item)
  30.  
  31.  
  32. if __name__ == '__main__':
  33.     if use_argv:
  34.         if sys.platform() == 'win':
  35.             matchObj = re.match(windows_compare + r"(.*?)\\.*", sys.argv[2], re.M | re.I)
  36.         else:
  37.             matchObj = re.match(main_download_dir + r"(.*?)/.*", sys.argv[2], re.M | re.I)
  38.         new_path = main_download_dir + matchObj.group(1)
  39.         #print(new_path)
  40.         extract(new_path)
  41.     else:
  42.         #extract("D:/DownloadsCompleted")
  43.         for c, argument in enumerate(sys.argv[0:]):
  44.             f = open('python.txt', 'a')
  45.             f.writelines(str(c) + argument + "\n")
  46.             f.close()
  47.             print(str(c) + " : " + argument)
Advertisement
Add Comment
Please, Sign In to add comment