# -*- coding: utf-8 -*-
"""Kodi context menu entry point (docs/plan/skin-milionar/080 §3): library item -> addon action."""
import sys

import xbmc


def main():
    action = sys.argv[1] if len(sys.argv) > 1 else ''
    tag = sys.listitem.getVideoInfoTag()
    dbtype, dbid = tag.getMediaType(), tag.getDbId()
    if action.startswith('lib_') and dbtype in ('movie', 'tvshow', 'episode') and dbid and dbid > 0:
        xbmc.executebuiltin(
            'RunPlugin(plugin://plugin.video.milionar/?action={}&dbtype={}&dbid={})'.format(action, dbtype, dbid))


if __name__ == '__main__':
    main()
