# -*- coding: utf-8 -*-
import urllib
from Components.Sources.Source import Source

class Sr(Source):
	def __init__(self, session):
		Source.__init__(self)
		self.session = session
	
	def handleCommand(self, cmd):
		from Plugins.Bp.geminimain.plugin import cgevent, BG_STREAM
		from Plugins.Bp.geminimain.gTools import libgeminimain, pathExists
		from Plugins.Bp.geminidreamnetcast.plugins.exPlugin import exPlugin
		from time import sleep
		
		if cmd["conststream"] is not None or cmd["conststream"] == "":
			cgevent.setConfig("SR_conststream", 1)
		else:
			cgevent.setConfig("SR_conststream", 0)
			
		if cmd["recpath"] != "" and cgevent.getConfig("SR_path","/media/hdd") != cmd["recpath"] and pathExists(cmd["recpath"]):
			cgevent.setConfig("SR_path",cmd["recpath"])
			
		if bool(libgeminimain.getBGstatus() & BG_STREAM):
			exPlugin.stop()
			sleep(30)
		else:
			# session only for current service
			exPlugin.start(self.session, web=True)
