diff --git a/main.py b/main.py index d9cdf6c..1217022 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,7 @@ -import os, eyed3, re, shutil +import os, eyed3, re, shutil, sys, getopt -path = input('Enter to full path to the directory containing you files: ') -dest = input('Enter the full path to the destination: ') - -with os.scandir(path) as dir_entries: - for entry in dir_entries: +def organizeFiles(path, dest): + with os.scandir(path) as dir_entries: for entry in dir_entries: if bool(re.search(r'.*\.mp3', entry.name)) is True: file = eyed3.load(entry) @@ -12,7 +9,6 @@ with os.scandir(path) as dir_entries: artist = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', artist) album = file.tag.album album = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', album) - artistIsExist = os.path.exists(f'{dest}\\{artist}') if not artistIsExist: os.makedirs(f'{dest}\\{artist}') @@ -23,7 +19,23 @@ with os.scandir(path) as dir_entries: song = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\-)|(\|)|(\ )$', '', song) song = re.sub(r'\ +', ' ', song) try: - shutil.copy(entry.path, str(f'{dest}\\{artist}\\{album}\{song}')) + shutil.move(entry.path, str(f'{dest}\\{artist}\\{album}\{song}')) except: print(song) +def main(argv): + if len(argv) == 0: + print('Usage: main.py -s SOURCE_DIR -d DEST_DIR') + else: + opts, args = getopt.getopt(argv, "s:d:") + for opt, arg in opts: + if opt == '-s': + path = arg + elif opt == '-d': + dest = arg + try: + organizeFiles(path, dest) + except: + print('Arguments not entered correctly') +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file