# -*- coding: utf-8 -*-
import os,os.path,sys, urllib, traceback
from kodiswift import Plugin, ListItem, storage
from kodiswift import xbmc, xbmcgui, xbmcplugin, xbmcvfs, CLI_MODE
#from resources.lib import ContentSources, util
#sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),"resources","lib","sources"))
from  resources.lib.content import playstreamproxy
try:
    import wingdbstub
except:
    pass

#monitor = xbmc.Monitor()

plugin = Plugin()
plugin.load_addon_settings()
autostart = plugin.get_setting("general_autostart", bool)
if autostart:
    xbmc.executebuiltin("RunAddon(plugin.video.playstream)")
# view_mode = plugin.get_setting("view_mode", str)
port = plugin.get_setting("general_port",int)
start_proxy = plugin.get_setting("general_proxy",bool)
host = "localhost"
if start_proxy:
    plugin.notify("Starting playstreamproxy","Info",10000, xbmcgui.NOTIFICATION_INFO)
    try:
        playstreamproxy.start(host, port)
    except Exception as e:
        xbmcgui.Dialog().ok("Error starting playstreamproxyserver",unicode(e))
        #plugin.notify(unicode(e), "Error", 10000, xbmcgui.NOTIFICATION_ERROR)
        traceback.print_exc()
