Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulchabanon committed Apr 2, 2016
0 parents commit 5faaa55
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autofileaway.rules.csv
autofileaway.log
61 changes: 61 additions & 0 deletions autofileaway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import re
import csv
import shutil
import datetime

excludeFormat = ['.+\.part$','.+\.crdownload$']
rootDir = os.path.dirname(os.path.abspath(__file__))

def logDate():
return '['+str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))+'] '

log = open(rootDir+'/autofileaway.log', 'a')
with open(rootDir+'/autofileaway.rules.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
for rows in spamreader:
if len(rows) < 3:
continue

srcFolder = rows[0]
srcFormat = rows[1]
dstFolder = rows[2]

# go thru files
for f in os.listdir(srcFolder):
exclude = False
for ef in excludeFormat:
if re.search(ef, f):
print f, 'match exclude rule', ef
exclude = True
continue

if not exclude and re.search(srcFormat, f):
if len(rows) > 3:
dstFormat = rows[3]
print f, 'match', srcFormat, '->', dstFormat
dstFileName = re.sub(srcFormat, dstFormat, f)
else:
print f, 'match', srcFormat
dstFileName = f

srcFull = srcFolder+'/'+f
dstFull = dstFolder+'/'+dstFileName

if os.path.isdir(srcFull):
print srcFull, 'is a folder, skipping'
continue

print srcFull, 'renamed', dstFull

if os.path.exists(dstFull):
log.write(logDate()+'Already exists\n')
log.write(logDate()+dstFull+'\n\n')
continue

shutil.move(srcFull, dstFull)
log.write(logDate()+srcFull+'\n')
log.write(logDate()+dstFull+'\n\n')

log.close()

7 changes: 7 additions & 0 deletions autofileaway.rules.csv.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# YouTube formating
"/home/user/Downloads","(.+)\([0-9]{3,4}p_.+-.+\)\.(.+)","/home/user/Downloads","\1.\2"
"/home/user/Downloads","(.+) \([0-9]{3,4}p\)\.(.+)","/home/user/Downloads","\1.\2"
"/home/user/Downloads","(.+) \([0-9]{3,4}p [0-9][0-9]fps\)\.(.+)","/home/user/Downloads","\1.\2"

# Other things you want to move
"/home/user/Downloads",".*(?i)hunter[_ -]x[_ -]hunter.*[_ -]([0-9]{2}).*\.([A-z0-9]{3})$","/media/user/media-disk/manga/Hunter x Hunter 2011","Hunter x Hunter \1.\2"

0 comments on commit 5faaa55

Please sign in to comment.