Coverage for lib/lottie/importers/dot_lottie.py: 0%
24 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-20 16:17 +0100
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-20 16:17 +0100
1import json
2import zipfile
4from .base import importer
5from ..parsers.baseporter import ExtraOption
6from ..parsers.tgs import parse_tgs
7from ..objects import Animation, assets
10@importer("dotLottie Archive", ["lottie"], [
11 ExtraOption("id", help="ID of the animation to extract", default=None)
12], slug="dotlottie")
13def import_dotlottie(file, id=None):
14 with zipfile.ZipFile(file) as zf:
15 with zf.open("manifest.json") as manifest:
16 meta = json.load(manifest)
18 if id is None:
19 id = meta["animations"][0]["id"]
21 info = zf.getinfo("animations/%s.json" % id)
23 with zf.open(info) as animfile:
24 an = Animation.load(json.load(animfile))
25 if an.assets:
26 for asset in an.assets:
27 if isinstance(asset, assets.Image) and not asset.is_embedded:
28 fname = asset.path + asset.file_name
29 if fname in zf.namelist():
30 with zf.open(fname) as imgfile:
31 asset.load(imgfile)
32 return an