forked from tom-kerr/bookmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmaker.py
executable file
·99 lines (77 loc) · 3.64 KB
/
bookmaker.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
#!/usr/bin/env python3
""" Commandline entry point
"""
import sys, argparse
import logging
from util import Util
from environment import Environment; Environment('shell')
from processing import ProcessHandling
def main(args):
try:
books = Environment.get_books(args.root_dir, args, stage='process')
except Exception as e:
Util.bail(str(e))
P = ProcessHandling()
queue = P.new_queue()
for book in books:
queue.add(book, cls='FeatureDetection', mth='pipeline')
if args.derive_all or args.derive:
if args.derive:
formats = args.derive
else:
formats = ('djvu', 'pdf', 'epub', 'text')
if book.settings['respawn']:
queue.add(book, cls='Crop', mth='cropper_pipeline',
kwargs={'crop': 'standardCrop'})
queue.add(book, cls='OCR', mth='tesseract_hocr_pipeline',
kwargs={'lang': args.language})
if 'djvu' in formats:
queue.add(book, cls='Djvu', mth='make_djvu_with_c44')
if 'pdf' in formats:
queue.add(book, cls='PDF', mth='make_pdf_with_hocr2pdf')
if 'epub' in formats:
queue.add(book, cls='EPUB', mth='make_epub')
if 'text' in formats:
queue.add(book, cls='PlainText', mth='make_full_plain_text')
queue.drain('sync')
if __name__ == "__main__":
parser = argparse.ArgumentParser('./bookmaker')
argu = parser.add_argument_group('Required')
argu.add_argument('--root-dir', nargs='*', required=True,
help='A single item or a directory of items')
settings = parser.add_argument_group('Settings')
settings.add_argument('--save-settings', action='store_true',
help='Saves arguments to settings.yaml')
proc = parser.add_argument_group('Processing')
proc.add_argument('--respawn', action='store_true',
help='Files/Data will be re-created (default)')
proc.add_argument('--no-respawn', action='store_true',
help='Files/Data will be not be re-created')
ocr = parser.add_argument_group('OCR')
ocr.add_argument('--language', nargs='?', default='English')
derive = parser.add_argument_group('Derivation')
derive.add_argument('--active-crop', nargs='?', default='standardCrop')
derive.add_argument('--derive', nargs='+',
help='Formats: djvu, pdf, epub, text')
derive.add_argument('--derive-all', action='store_true',
help='Derive all formats')
debug = parser.add_argument_group('Debug')
debug.add_argument('--make-cornered-scaled',
action='store_true', default=None)
debug.add_argument('--draw-clusters',
action='store_true', default=None)
debug.add_argument('--draw-removed-clusters',
action='store_true', default=None)
debug.add_argument('--draw-invalid-clusters',
action='store_true', default=None)
debug.add_argument('--draw-content-dimensions',
action='store_true', default=None)
debug.add_argument('--draw-page-number-candidates',
action='store_true', default=None)
debug.add_argument('--draw-noise', action='store_true')
if len(sys.argv)<2:
parser.print_help()
sys.exit(0);
else:
args = parser.parse_args()
main(args)