-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse_comics.py
111 lines (78 loc) · 2.99 KB
/
parse_comics.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os, sys
import zipfile
import rarfile
import tarfile
# root = "C:\cygwin64\home\Paola\src\hbproject\static\comic_test"
# class Unpacker(object):
# def __init__(self, filetype):
# self.filetype = os.path.splitext(filetype)[-1].lower()
def find_images(folder,img_type):
"""
Traverse folder directory and find images
"""
pass
def unpack_comics(root):
"""
Extracts rars from rarfile.
Makes folder for all images.
RETURNS: PATH to folder, and cover image in folder.
"""
# import pdb; pdb.set_trace()
ALLOWED_EXTENSIONS = set(['.cbr','.cbz','.cbt'])
for f in os.listdir(root):
my_file = ""
issue_path = ""
icover_path = ""
filetype = ''
opened_file = ""
print "Start: ","@"*40
print "ThiS IS F", f
filetype = os.path.splitext(f)[1].lower()
print "my filetype is : ",filetype
print "ROOT: ", root
folder_path = os.path.splitext(f)[0]
print "folder [0]: ", folder_path
my_file = os.path.join(root, f)
print my_file
if os.path.isdir(my_file) == False and filetype in ALLOWED_EXTENSIONS:
save_to = os.path.join(root, folder_path)
print "SAVE TO: ", save_to
if filetype == ".cbr":
opened_file = rarfile.RarFile(my_file, 'r')
print "Its a ", filetype
elif filetype == ".cbz":
opened_file = zipfile.ZipFile(my_file, 'r')
print "Its a ", filetype
elif filetype == ".cbt":
opened_file = tarfile.TarFile(my_file, 'r')
print "Its a ", filetype
opened_file.extractall(save_to)
#REMOVES THE EXTENSION FROM ZIP FILE PATH
issue_path = sorted(opened_file.namelist())[0]
print folder_path
print "issue path: " ,issue_path
#MAKES PATH TO FIRST IMAGE IN THE ISSUE
print "BEFORE JOIN: ", issue_path
issue_path = save_to
print "AFTER JOIN: ", issue_path
print "*"*10
new_folder = os.listdir(issue_path)[0]
check = os.path.join(issue_path,new_folder)
print "WTFMATE?!",new_folder
print "is this directory: ",os.path.isdir(check)
if os.path.isdir(check)==False:
icover_path = new_folder
print "no reason a folder should be in here"
else:
print folder_path
print new_folder
issue_path = os.path.join(issue_path, new_folder)
icover_path = os.listdir(issue_path)[0]
folder_path = os.path.join(folder_path,new_folder)
print "folder_path: ",folder_path
print "issue_path: ",issue_path
print "cover path: ", icover_path
# else:
# print "###WHAT IS THIS###"
# print os.listdir(folder_path)
return [issue_path,icover_path,folder_path]