-
Notifications
You must be signed in to change notification settings - Fork 10
/
kindleShowHead.py
78 lines (63 loc) · 2 KB
/
kindleShowHead.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
# encoding: utf-8
import sys
import os.path
import getopt
import Tkinter
from kindleunpack.utf8_utils import utf8_argv, add_cp65001_codec, set_utf8_default_encoding, utf8_str
from kindleunpack.mobi_sectioner import Sectionizer, describe
from kindleunpack.mobi_header import MobiHeader, dump_contexth
def getEpubHead():
pass
def guiShow(headers, filePath):
top = Tkinter.Tk()
top.title(filePath)
text = Tkinter.Text(height=25, width=80, font='SimSun')
text.insert(Tkinter.INSERT, '\n'.join(headers))
text.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) # 将按钮pack,充满整个窗体(只有pack的组件实例才能显示)
# cnames = StringVar()
# cnames.set(tuple(headers))
# Listbox(top, listvariable=cnames, width=100).grid()
top.mainloop()
def showBookInfo(infile):
ext = os.path.splitext(infile)[1]
if ext in ['.epub']:
headers = getEpubHead(infile)
else:
sect = Sectionizer(infile)
if sect.ident != 'BOOKMOBI' and sect.ident != 'TEXtREAd':
raise 'Invalid file format'
mh = MobiHeader(sect,0)
headers = mh.get_exth(ext[1:])
guiShow(headers, infile)
def usage(progname):
print("")
print("Description:")
print(" Simple Program to show Mobi/azw3 Meta Info.")
print(" ")
print("Usage:")
print(" %s infile.mobi" % progname)
print(" ")
print("Options:")
print(" -h print this help message")
def main(argv=utf8_argv()):
print("Mobi Show Meta 1.0")
progname = os.path.basename(argv[0])
try:
opts, args = getopt.getopt(argv[1:], "h")
except getopt.GetoptError, err:
print str(err)
usage(progname)
sys.exit(2)
if len(args) != 1:
usage(progname)
sys.exit(2)
for o, a in opts:
if o == "-h":
usage(progname)
sys.exit(0)
infile = args[0]
showBookInfo(infile)
if __name__ == '__main__':
add_cp65001_codec()
set_utf8_default_encoding()
sys.exit(main())