Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import patoolib
- from os import listdir, remove
- from shutil import rmtree
- from os.path import isfile, join, isdir
- import re
- use_argv = True
- main_download_dir = "D:/DownloadsCompleted/"
- if sys.platform() == 'win':
- windows_compare = main_download_dir.replace("/", "\\\\")
- def extract(path, deleteonly=True):
- # Extract file
- onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
- onlydirs = [f for f in listdir(path) if isdir(join(path, f))]
- if not deleteonly:
- for f in onlyfiles:
- if f.endswith(".rar"):
- rar = path + "/" + f
- patoolib.extract_archive(rar, outdir=path)
- # Removal of unwanted files
- for item in onlydirs:
- rmtree(path + "/" + item)
- for item in onlyfiles:
- if item.endswith(".mkv") == False:
- remove(path + "/" + item)
- if __name__ == '__main__':
- if use_argv:
- if sys.platform() == 'win':
- matchObj = re.match(windows_compare + r"(.*?)\\.*", sys.argv[2], re.M | re.I)
- else:
- matchObj = re.match(main_download_dir + r"(.*?)/.*", sys.argv[2], re.M | re.I)
- new_path = main_download_dir + matchObj.group(1)
- #print(new_path)
- extract(new_path)
- else:
- #extract("D:/DownloadsCompleted")
- for c, argument in enumerate(sys.argv[0:]):
- f = open('python.txt', 'a')
- f.writelines(str(c) + argument + "\n")
- f.close()
- print(str(c) + " : " + argument)
Advertisement
Add Comment
Please, Sign In to add comment