# -*- coding: utf-8 -*-
from Plugins.Bp.geminimain.gLocale import _
from Plugins.Bp.geminimain.gTools import pathExists, gPluginPath

from enigma import eEnv
from Plugins.Plugin import PluginDescriptor
from Plugins.Extensions.WebInterface.WebChilds.Screenpage import ScreenPage
from Plugins.Extensions.WebInterface.WebChilds.Toplevel import addExternalChild

from time import strftime, localtime, time as getTime
from twisted.web import static
from twisted.python import util

#---------------------------------------------------------------------



# dreamnetstart plugin -----------------------------------------------
def dreamnetstart(session, **kwargs):
	from gsr import Cgsr
	session.open(Cgsr)
	
# webif --------------------------------------------------------------
if hasattr(static.File, "render_GET"):
	class File(static.File):
		def render_POST(self, request):
			return self.render_GET(request)
else:
	File = static.File
	
# autostart webif hasWebif -------------------------------------------
def hasWebif():
	file = gPluginPath + "gemininetcastwebif/plugin.py"
	if pathExists(file):
		return True
	else:
		return False

# autostart webif plugin ---------------------------------------------
def autostart(reason, **kwargs):
	if reason == 0 and "session" in kwargs and hasWebif():
		session = kwargs["session"]
		root = File(eEnv.resolve("${libdir}/enigma2/python/Plugins/Bp/geminisr/web-data"))
		root.putChild("web", ScreenPage(session, util.sibpath(__file__, "web"), True) )
		addExternalChild( ("streamripper", root) )

#Descriptor plugin, webif plugin--------------------------------------
def Plugins(**kwargs):
	return [PluginDescriptor(name=_("Streamripper"),
				description=_("recording audio internet streams"),
				where = PluginDescriptor.WHERE_EXTENSIONSMENU,
				fnc=dreamnetstart,
				icon="icon_gsr.png"),
			PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART,
				fnc = autostart)]
