-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSort_Pelis.py
54 lines (47 loc) · 1.67 KB
/
Sort_Pelis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import re
import os
import sys
import shutil
import logging
DIR = "/Users/Cibeles/PycharmProjects/MelaUtils/Descargas"
LOGFILE = "/Users/Cibeles/PycharmProjects/MelaUtils/flexget/flexget.log"
LOGFORMAT = "[%(asctime)s - %(levelname)s] %(message)s"
PELIS_HOME="/Users/Cibeles/PycharmProjects/MelaUtils/Pelis"
#DIR = "/Volumes/Vault/Descargas/"
#LOGFILE = "/Volumes/Vault/flexget/flexget.log"
#PELIS_HOME="/Volumes/Vault/Peliculas"
nombre_dir = os.listdir(DIR)
fobj = sys.stdout
ftype_reg_exp = re.compile('.*\.(avi|mkv|mp4|mpg|mpeg)$')
ftype_serie_regex = re.compile('.+(S[0-9]{2}|s[0-9]{2}).*')
formatter = logging.Formatter(LOGFORMAT)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# file handler
file = logging.FileHandler(LOGFILE)
#file.setLevel(logging.INFO)
file.setFormatter(formatter)
logger.addHandler(file)
# console handler
console = logging.StreamHandler()
#console.setLevel(logging.INFO)
console.setFormatter(formatter)
logger.addHandler(console)
try:
fobj = open(LOGFILE, 'a')
except Exception as e:
if e.errno == 2:
print "No se pueden escribir logs, el path no existe: " + e.strerror
for peli in nombre_dir:
cwd = DIR + '/' + peli
#print "directorio " + cwd
if not (ftype_serie_regex.match(cwd)):
#os.path.isdir(cwd) or os.path.isfile(cwd) ) and
logger.info(cwd + " no es una serie, se movera a " + PELIS_HOME)
try:
shutil.move(cwd,PELIS_HOME)
logger.info(cwd + " movido exitosamente")
except Exception, e:
logger.error(cwd + " no se ha podido mover a " + PELIS_HOME + "el directorio ya existe")
else:
logger.warn(cwd + " es una serie, no una peli, no se movera.")