-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcontent_kinds.py
68 lines (53 loc) · 1.43 KB
/
content_kinds.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
import json
import pkgutil
from collections import namedtuple
from le_utils.constants import file_formats
""" Content Kind Constants """
# IMPORTANT: Keep these constants in sync with kindlookup.json and presetlookup.json
TOPIC = "topic"
VIDEO = "video"
AUDIO = "audio"
EXERCISE = "exercise"
DOCUMENT = "document"
HTML5 = "html5"
SLIDESHOW = "slideshow"
H5P = "h5p"
ZIM = "zim"
QUIZ = "quiz"
choices = (
(TOPIC, "Topic"),
(VIDEO, "Video"),
(AUDIO, "Audio"),
(EXERCISE, "Exercise"),
(DOCUMENT, "Document"),
(HTML5, "HTML5 App"),
(SLIDESHOW, "Slideshow"),
(H5P, "H5P"),
(ZIM, "Zim"),
(QUIZ, "Quiz"),
)
""" File Format (extension) to Content Kind Mapping """
MAPPING = {
file_formats.MP4: VIDEO,
file_formats.WEBM: VIDEO,
file_formats.MP3: AUDIO,
file_formats.PDF: DOCUMENT,
file_formats.EPUB: DOCUMENT,
file_formats.PERSEUS: EXERCISE,
file_formats.HTML5: HTML5,
file_formats.H5P: H5P,
file_formats.ZIM: ZIM,
file_formats.BLOOMPUB: DOCUMENT,
file_formats.BLOOMD: DOCUMENT,
}
class Kind(namedtuple("Kind", ["id", "name"])):
pass
def generate_list(constantlist):
for id, kind in constantlist.items():
yield Kind(id=id, **kind)
def _initialize_kind_list():
constantlist = json.loads(
pkgutil.get_data("le_utils", "resources/kindlookup.json").decode("utf-8")
)
return generate_list(constantlist)
KINDLIST = list(_initialize_kind_list())