python-lottie  0.6.11+deved4e6c7
A framework to work with lottie files and telegram animated stickers (tgs)
dot_lottie.py
Go to the documentation of this file.
1 import json
2 import zipfile
3 
4 from .base import importer
5 from ..parsers.baseporter import ExtraOption
6 from ..parsers.tgs import parse_tgs
7 from ..objects import Animation, assets
8 
9 
10 @importer("dotLottie Archive", ["lottie"], [ ExtraOption("id", help="ID of the animation to extract", default=None)
11 ], slug="dotlottie")
12 def import_dotlottie(file, id=None):
13  with zipfile.ZipFile(file) as zf:
14  with zf.open("manifest.json") as manifest:
15  meta = json.load(manifest)
16 
17  if id is None:
18  id = meta["animations"][0]["id"]
19 
20  info = zf.getinfo("animations/%s.json" % id)
21 
22  with zf.open(info) as animfile:
23  an = Animation.load(json.load(animfile))
24  if an.assets:
25  for asset in an.assets:
26  if isinstance(asset, assets.Image) and not asset.is_embedded:
27  fname = asset.image_path + asset.image
28  if fname in zf.namelist():
29  with zf.open(fname) as imgfile:
30  asset.load(imgfile)
31  return an
32 
def import_dotlottie(file, id=None)
Definition: dot_lottie.py:12