-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookFileType.py
More file actions
120 lines (86 loc) · 2.67 KB
/
BookFileType.py
File metadata and controls
120 lines (86 loc) · 2.67 KB
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
110
111
112
113
114
115
116
117
118
119
120
import abc
from Parsers.OPF_Parser import OPF_Parser
#====================================================#
# Purpose: Represent the actual type of different #
# types of books that may need to be #
# processed (ex. EPUB, MP3, DAISY, etc...) #
# Properties: name - The name of the type #
# property_list - The list of POTENTIAL #
# metadata avaiable for #
# that type #
#====================================================#
class BookFileType(object):
__metaclass__ = abc.ABCMeta
name = ''
@abc.abstractmethod
def check_extension():
return
class EPUB_Type(BookFileType):
def __init__(self):
self.name = 'EPUB'
@staticmethod
def check_extension(extension):
isEPUB = False
if extension == 'epub':
isEPUB = True
return isEPUB
def get_metadata(self, filepath):
return_result = None
opf_parser = OPF_Parser(filepath)
return_result = opf_parser.get_metadata()
return return_result
class MP3_Type(BookFileType):
def __init__(self):
self.name = 'MP3'
@staticmethod
def check_extension(extension):
isMP3 = False
if extension == 'mp3':
isMP3 = True
return isMP3
class DAISY_Type(BookFileType):
def __init__(self):
self.name = 'DAISY'
@staticmethod
def check_extension(extension):
isDAISY = False
# Because this type isn't determined by extension skip this
return isDAISY
def check_string(self, token):
isDAISY = False
if token.startswith('DAISY'):
isDAISY = True
return isDAISY
class DAISY202_Type(DAISY_Type):
def __init__(self):
self.name = 'DAISY 2.02'
def check_string(self, token):
isDAISY = False
if super(DAISY202_Type, self).check_string(token):
if token.endswith('202'):
isDAISY = True
return isDAISY
class DAISY3_Type(DAISY_Type):
def __init__(self):
self.name = 'DAISY 3'
def check_string(self, token):
isDAISY = False
if super(DAISY3_Type, self).check_string(token):
if token.endswith('3'):
isDAISY = True
return isDAISY
class BookFileTypeFactory(object):
@staticmethod
def getExtensionType(extension):
returnType = None
for type in [EPUB_Type, MP3_Type, DAISY_Type]:
if type.check_extension(extension):
returnType = type()
return returnType
def getStringType(self, token):
returnType = None
for type in [DAISY202_Type,DAISY3_Type]:
caller = type()
if caller.check_string(token):
returnType = type()
return returnType