-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcbrconverter.py
87 lines (67 loc) · 2.21 KB
/
cbrconverter.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import patoolib
import os
from os.path import basename
import re
import json
import shutil
import xml.etree.cElementTree as ET
import glob
from zipfile import ZipFile
from modifieddate import datemodified
def cbzgenerator(namefile, origen):
logfile = origen + '/cbrconverter.log'
parents, filename = os.path.split(namefile)
temporal = parents + '/temporal'
try:
os.mkdir(temporal)
except OSError:
print ("Creation of the directory %s failed" % temporal)
print(namefile)
try:
patoolib.extract_archive(namefile, outdir=temporal)
except:
f = open(logfile, "a")
f.write("Error descomprimiendo: " + namefile + '\n')
f.close()
try:
shutil.rmtree(temporal)
except OSError:
print('Error while deleting directory')
os.rename(namefile, namefile + ".extraido")
archivos = glob.glob(temporal + '/**/*.*', recursive=True)
archivos.sort()
filename2, file_extension = os.path.splitext(filename)
cbz = parents + '/' + filename2 + '.cbz.new'
zipobje = ZipFile(cbz, 'w')
for archivos2 in archivos:
datemodified(archivos2)
ruta, nombrearchivo = os.path.split(archivos2)
zipobje.write(archivos2, basename(nombrearchivo))
zipobje.close()
try:
shutil.rmtree(temporal)
except:
print('Error while deleting directory')
def main():
path = "/media/cristian/Datos/Downloads/Comics"
# path = "/media/cristian/Datos/Comics/Buffer/cbr"
files = glob.glob(path + '/**/*.[cC][bB][rR]', recursive=True)
files2 = glob.glob(path + '/**/*.[cC][bB][zZ]', recursive=True)
# print(files)
# print(files2)
# for ficheros in files:
# parents, filename = os.path.split(ficheros)
for ficheros in files:
cbzgenerator(ficheros,path)
for ficheros2 in files2:
cbzgenerator(ficheros2,path)
if __name__ == "__main__":
main()
# temporal = path + "/temporal"
# try:
# os.mkdir(temporal)
# except OSError:
# print ("Creation of the directory %s failed" % temporal)
# # filename, file_extension = os.path.splitext(ficheros)
# filename = path +
# patoolib.extract_archive("foo_bar.rar", outdir=)