#!/usr/bin/env python
# coding=utf8
# This file is part of PlayStream - enigma2 plugin to play video streams from various sources
# Copyright (c) 2016 ivars777 (ivars777@gmail.com)

import os, traceback
from Plugins.Plugin import PluginDescriptor
from Components.Language import language
import PlayStream as plugin
from plugin_locale import _, locale_init


# lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
# os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
locale_init(plugin.__title__,"locale")
language.addCallback(locale_init)


def main(session, **kwargs):
    try:
        reload(plugin)
        session.open(plugin.MainScreen)
    except Exception as e:
        print "Error loading PlayStream - "+ e.message
        traceback.print_exc()


def menu(menuid, **kwargs):
    if menuid == "mainmenu":
        return [(plugin.__title__, main, plugin.__id__, 57)]
    return []


def Plugins(**kwargs):
    return [
        PluginDescriptor(name = plugin.__title__, description = plugin.__desc__, where = [PluginDescriptor.WHERE_PLUGINMENU,PluginDescriptor.WHERE_EXTENSIONSMENU], icon = "plugin.png", fnc = main),
        PluginDescriptor(name=plugin.__title__, description = plugin.__desc__, where = [PluginDescriptor.WHERE_MENU], fnc=menu)
    ]
