Added cli options
This commit is contained in:
parent
0634c8b56e
commit
3484637914
26
main.py
26
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: ')
|
|
||||||
|
|
||||||
|
def organizeFiles(path, dest):
|
||||||
with os.scandir(path) as dir_entries:
|
with os.scandir(path) as dir_entries:
|
||||||
for entry in dir_entries:
|
|
||||||
for entry in dir_entries:
|
for entry in dir_entries:
|
||||||
if bool(re.search(r'.*\.mp3', entry.name)) is True:
|
if bool(re.search(r'.*\.mp3', entry.name)) is True:
|
||||||
file = eyed3.load(entry)
|
file = eyed3.load(entry)
|
||||||
|
@ -12,7 +9,6 @@ with os.scandir(path) as dir_entries:
|
||||||
artist = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', artist)
|
artist = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', artist)
|
||||||
album = file.tag.album
|
album = file.tag.album
|
||||||
album = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', album)
|
album = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', album)
|
||||||
|
|
||||||
artistIsExist = os.path.exists(f'{dest}\\{artist}')
|
artistIsExist = os.path.exists(f'{dest}\\{artist}')
|
||||||
if not artistIsExist:
|
if not artistIsExist:
|
||||||
os.makedirs(f'{dest}\\{artist}')
|
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)
|
||||||
song = re.sub(r'\ +', ' ', song)
|
song = re.sub(r'\ +', ' ', song)
|
||||||
try:
|
try:
|
||||||
shutil.copy(entry.path, str(f'{dest}\\{artist}\\{album}\{song}'))
|
shutil.move(entry.path, str(f'{dest}\\{artist}\\{album}\{song}'))
|
||||||
except:
|
except:
|
||||||
print(song)
|
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:])
|
Loading…
Reference in New Issue
Block a user