Skip to content

Instantly share code, notes, and snippets.

@evuez
Created May 2, 2015 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evuez/9c93fe9daed11286c14c to your computer and use it in GitHub Desktop.
Save evuez/9c93fe9daed11286c14c to your computer and use it in GitHub Desktop.
from shutil import move
from glob import glob
from os import path
from collections import Counter
HOME = '/home/evuez/'
RESERVED = ('QUEUED', 'TMP', 'DONE')
TORNT = ('.torrent',)
MUSIC = ('.mp3', '.ogg', '.wav')
MOVIE = ('.avi', '.mkv', '.mpg', '.mpeg')
IMAGE = ('.png', '.gif', '.jpg', '.jpeg', '.svg')
DCMNT = ('.pdf', '.doc', '.docx', '.ods', '.odp', '.odt', '.txt', '.epub', '.pptx')
def get_dir(f):
if f.endswith(TORNT):
return path.join(HOME, 'downloads/QUEUED')
elif f.endswith(MUSIC):
return path.join(HOME, 'music')
elif f.endswith(MOVIE):
return path.join(HOME, 'videos')
elif f.endswith(IMAGE):
return path.join(HOME, 'images')
elif f.endswith(DCMNT):
return path.join(HOME, 'documents')
for x in glob(path.join(HOME, 'downloads/*')):
if path.isfile(x):
new_dir = get_dir(x)
elif path.isdir(x):
filetypes = []
if x.endswith(RESERVED):
continue
for _ in glob(path.join(x, '*')):
filetypes.append(path.splitext(_)[1])
new_dir = get_dir(Counter(filetypes).most_common(1)[0][0])
if new_dir is not None:
move(x, new_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment