-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathfile_formats.py
134 lines (107 loc) · 2.75 KB
/
file_formats.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import json
import pkgutil
from collections import namedtuple
""" File Format Constants """
# IMPORTANT: Keep these constants in sync with formatlookup.json and presetlookup.json
# constants for Video format
MP4 = "mp4"
MP4_MIMETYPE = "video/mp4"
WEBM = "webm"
WEBM_MIMETYPE = "video/webm"
# constants for video formats converitble to mp4
AVI = "avi"
MOV = "mov"
MPG = "mpg"
WMV = "wmv"
MKV = "mkv"
FLV = "flv"
OGV = "ogv"
M4V = "m4v"
# constants for Subtitle format
VTT = "vtt"
VTT_MIMETYPE = ".vtt"
# constants for formats convertible to VTT
SRT = "srt"
TTML = "ttml"
SAMI = "sami"
SCC = "scc"
DFXP = "dfxp"
# constants for Audio format
MP3 = "mp3"
MP3_MIMETYPE = ".mp3"
# constants for Document format
PDF = "pdf"
PDF_MIMETYPE = "application/pdf"
# constants for Thumbnail format
JPG = "jpg"
JPG_MIMETYPE = "image/jpeg"
JPEG = "jpeg"
PNG = "png"
PNG_MIMETYPE = "image/png"
GIF = "gif"
GIF_MIMETYPE = "image/gif"
JSON = "json"
JSON_MIMETYPE = "application/json"
SVG = "svg"
SVG_MIMETYPE = "image/svg"
GRAPHIE = "graphie"
GRAPHIE_MIMETYPE = ".graphie"
# constants for Exercise format
PERSEUS = "perseus"
PERSEUS_MIMETYPE = "application/perseus+zip"
# constants for HTML5 zip format
HTML5 = "zip"
HTML5_MIMETYPE = ".zip"
# constants for H5P format
H5P = "h5p"
H5P_MIMETYPE = ".h5p"
# constants for Zim format
ZIM = "zim"
ZIM_MIMETYPE = ".zim"
# constants for ePub format
EPUB = "epub"
EPUB_MIMETYPE = "application/epub+zip"
# constants for bloomPub format
BLOOMPUB = "bloompub"
BLOOMD = "bloomd"
BLOOMPUB_MIMETYPE = "application/bloompub+zip"
choices = (
(MP4, "MP4 Video"),
(WEBM, "WEBM Video"),
(VTT, "VTT Subtitle"),
(MP3, "MP3 Audio"),
(PDF, "PDF Document"),
(JPG, "JPG Image"),
(JPEG, "JPEG Image"),
(PNG, "PNG Image"),
(GIF, "GIF Image"),
(JSON, "JSON"),
(SVG, "SVG Image"),
(PERSEUS, "Perseus Exercise"),
(GRAPHIE, "Graphie Exercise"),
(HTML5, "HTML5 Zip"),
(H5P, "H5P"),
(ZIM, "ZIM"),
(EPUB, "ePub Document"),
(BLOOMPUB, "Bloom Document"),
(BLOOMD, "Bloom Document"),
)
class Format(namedtuple("Format", ["id", "mimetype"])):
pass
def generate_list(constantlist):
for id, format in constantlist.items():
yield Format(id=id, **format)
def _initialize_format_list():
constantlist = json.loads(
pkgutil.get_data("le_utils", "resources/formatlookup.json").decode("utf-8")
)
return generate_list(constantlist)
FORMATLIST = list(_initialize_format_list())
_FORMATLOOKUP = {f.id: f for f in FORMATLIST}
def getformat(id, default=None):
"""
Try to lookup a file format object for its `id` in internal representation defined
in resources/formatlookup.json.
Returns None if lookup by internal representation fails.
"""
return _FORMATLOOKUP.get(id) or None