python-lottie  0.6.11+devcecd248
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"], [
11  ExtraOption("id", help="ID of the animation to extract", default=None)
12 ], slug="dotlottie")
13 def 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)
17 
18  if id is None:
19  id = meta["animations"][0]["id"]
20 
21  info = zf.getinfo("animations/%s.json" % id)
22 
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.image_path + asset.image
29  if fname in zf.namelist():
30  with zf.open(fname) as imgfile:
31  asset.load(imgfile)
32  return an
lottie.importers.dot_lottie.import_dotlottie
def import_dotlottie(file, id=None)
Definition: dot_lottie.py:13
lottie.parsers.baseporter.ExtraOption
Definition: baseporter.py:32
lottie.importers.base.importer
importer
Definition: base.py:21