Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Release History
===============

Unreleased
----------
- `file_formats` mimetype `vtt`: `.vtt` → `text/vtt`
- `file_formats` mimetype `mp3`: `.mp3` → `audio/mpeg`
- `file_formats` mimetype `zip`: `.zip` → `application/zip`
- `file_formats` mimetype `svg`: `image/svg` → `image/svg+xml`
- `file_formats` mimetype `h5p`: `.h5p` → `application/h5p+zip`
- `file_formats` mimetype `zim`: `.zim` → `application/x-openzim`
- `file_formats` mimetype `graphie`: `.graphie` → `application/x-graphie`
- `file_formats.getformat(id, default)` returns `default` for an unknown `id`
- Removed `resources/formatlookup.json`; use `file_formats.FORMATLIST`
- Added `kolibri-constants/FileFormats`


0.2.17 Apr 13, 2026
-------------------
- Added library enum constants (KOLIBRI, COMMUNITY) for identifying channel library membership
Expand Down
80 changes: 80 additions & 0 deletions js/FileFormats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// -*- coding: utf-8 -*-
// Generated by scripts/generate_from_specs.py
// FileFormats

export default {
MP4: "mp4",
MP4_MIMETYPE: "video/mp4",
WEBM: "webm",
WEBM_MIMETYPE: "video/webm",
VTT: "vtt",
VTT_MIMETYPE: "text/vtt",
PDF: "pdf",
PDF_MIMETYPE: "application/pdf",
EPUB: "epub",
EPUB_MIMETYPE: "application/epub+zip",
MP3: "mp3",
MP3_MIMETYPE: "audio/mpeg",
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+xml",
GRAPHIE: "graphie",
GRAPHIE_MIMETYPE: "application/x-graphie",
PERSEUS: "perseus",
PERSEUS_MIMETYPE: "application/perseus+zip",
H5P: "h5p",
H5P_MIMETYPE: "application/h5p+zip",
ZIM: "zim",
ZIM_MIMETYPE: "application/x-openzim",
HTML5: "zip",
HTML5_MIMETYPE: "application/zip",
BLOOMPUB: "bloompub",
BLOOMPUB_MIMETYPE: "application/bloompub+zip",
BLOOMD: "bloomd",
HTML5_ARTICLE: "kpub",
HTML5_ARTICLE_MIMETYPE: "application/kpub+zip",
AVI: "avi",
MOV: "mov",
MPG: "mpg",
WMV: "wmv",
MKV: "mkv",
FLV: "flv",
OGV: "ogv",
M4V: "m4v",
SRT: "srt",
TTML: "ttml",
SAMI: "sami",
SCC: "scc",
DFXP: "dfxp",
};

export const FORMATLIST = [
{ id: "mp4", mimetype: "video/mp4" },
{ id: "webm", mimetype: "video/webm" },
{ id: "vtt", mimetype: "text/vtt" },
{ id: "pdf", mimetype: "application/pdf" },
{ id: "epub", mimetype: "application/epub+zip" },
{ id: "mp3", mimetype: "audio/mpeg" },
{ id: "jpg", mimetype: "image/jpeg" },
{ id: "jpeg", mimetype: "image/jpeg" },
{ id: "png", mimetype: "image/png" },
{ id: "gif", mimetype: "image/gif" },
{ id: "json", mimetype: "application/json" },
{ id: "svg", mimetype: "image/svg+xml" },
{ id: "graphie", mimetype: "application/x-graphie" },
{ id: "perseus", mimetype: "application/perseus+zip" },
{ id: "h5p", mimetype: "application/h5p+zip" },
{ id: "zim", mimetype: "application/x-openzim" },
{ id: "zip", mimetype: "application/zip" },
{ id: "bloompub", mimetype: "application/bloompub+zip" },
{ id: "bloomd", mimetype: "application/bloompub+zip" },
{ id: "kpub", mimetype: "application/kpub+zip" },
];
149 changes: 69 additions & 80 deletions le_utils/constants/file_formats.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,71 @@
import json
import pkgutil
from collections import namedtuple
# -*- coding: utf-8 -*-
# Generated by scripts/generate_from_specs.py
from __future__ import unicode_literals

""" File Format Constants """
from collections import namedtuple

# IMPORTANT: Keep these constants in sync with formatlookup.json and presetlookup.json
# FileFormats

# 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
VTT_MIMETYPE = "text/vtt"
PDF = "pdf"
PDF_MIMETYPE = "application/pdf"

# constants for Thumbnail format
EPUB = "epub"
EPUB_MIMETYPE = "application/epub+zip"
MP3 = "mp3"
MP3_MIMETYPE = "audio/mpeg"
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"
SVG_MIMETYPE = "image/svg+xml"
GRAPHIE = "graphie"
GRAPHIE_MIMETYPE = ".graphie"

# constants for Exercise format
GRAPHIE_MIMETYPE = "application/x-graphie"
PERSEUS = "perseus"
PERSEUS_MIMETYPE = "application/perseus+zip"

# constants for HTML5 zip format
HTML5 = "zip"
HTML5_MIMETYPE = ".zip"

# constants for Kolibri article zip format
HTML5_ARTICLE = "kpub"
HTML5_ARTICLE_MIMETYPE = "application/kpub+zip"

# constants for H5P format
H5P = "h5p"
H5P_MIMETYPE = ".h5p"

# constants for Zim format
H5P_MIMETYPE = "application/h5p+zip"
ZIM = "zim"
ZIM_MIMETYPE = ".zim"

# constants for ePub format
EPUB = "epub"
EPUB_MIMETYPE = "application/epub+zip"

# constants for bloomPub format
ZIM_MIMETYPE = "application/x-openzim"
HTML5 = "zip"
HTML5_MIMETYPE = "application/zip"
BLOOMPUB = "bloompub"
BLOOMD = "bloomd"
BLOOMPUB_MIMETYPE = "application/bloompub+zip"
BLOOMD = "bloomd"
HTML5_ARTICLE = "kpub"
HTML5_ARTICLE_MIMETYPE = "application/kpub+zip"
AVI = "avi"
MOV = "mov"
MPG = "mpg"
WMV = "wmv"
MKV = "mkv"
FLV = "flv"
OGV = "ogv"
M4V = "m4v"
SRT = "srt"
TTML = "ttml"
SAMI = "sami"
SCC = "scc"
DFXP = "dfxp"

# Zip-based formats identified by le_utils.archive.contents_sha256.
# FROZEN: ricecooker and Studio's upload Cloud Function pin this; removing a format orphans its index entries.
ARCHIVE_FORMATS = (HTML5, H5P, EPUB, HTML5_ARTICLE, BLOOMPUB, BLOOMD)
ARCHIVE_FORMATS = (
HTML5,
H5P,
EPUB,
HTML5_ARTICLE,
BLOOMPUB,
BLOOMD,
)

choices = (
(MP4, "MP4 Video"),
Expand Down Expand Up @@ -118,24 +96,35 @@ class Format(namedtuple("Format", ["id", "mimetype"])):


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}
for id, record in constantlist.items():
yield Format(id=id, **record)


FORMATLIST = [
Format(id="mp4", mimetype="video/mp4"),
Format(id="webm", mimetype="video/webm"),
Format(id="vtt", mimetype="text/vtt"),
Format(id="pdf", mimetype="application/pdf"),
Format(id="epub", mimetype="application/epub+zip"),
Format(id="mp3", mimetype="audio/mpeg"),
Format(id="jpg", mimetype="image/jpeg"),
Format(id="jpeg", mimetype="image/jpeg"),
Format(id="png", mimetype="image/png"),
Format(id="gif", mimetype="image/gif"),
Format(id="json", mimetype="application/json"),
Format(id="svg", mimetype="image/svg+xml"),
Format(id="graphie", mimetype="application/x-graphie"),
Format(id="perseus", mimetype="application/perseus+zip"),
Format(id="h5p", mimetype="application/h5p+zip"),
Format(id="zim", mimetype="application/x-openzim"),
Format(id="zip", mimetype="application/zip"),
Format(id="bloompub", mimetype="application/bloompub+zip"),
Format(id="bloomd", mimetype="application/bloompub+zip"),
Format(id="kpub", mimetype="application/kpub+zip"),
]

_FORMATLOOKUP = {r.id: r for r 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
return _FORMATLOOKUP.get(id, default)
62 changes: 0 additions & 62 deletions le_utils/resources/formatlookup.json

This file was deleted.

Loading
Loading