Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
from __future__ import print_function
from __future__ import division
# 
# 	Instant EPG Timer Plugin 
# 	(c) gutemine & Dreamy
#
instantepgtimer_version="1.2-r2"
#
from Components.PluginComponent import plugins
from Plugins.Plugin import PluginDescriptor
from Screens.Screen import Screen
from Components.SystemInfo import SystemInfo
import Screens.EpgSelection 
import Screens.EventView
import Screens.ChannelSelection
import Screens.InfoBarGenerics
import Screens.MovieSelection
from RecordTimer import RecordTimerEntry, RecordTimer, parseEvent, AFTEREVENT
from Components.Input import Input
from Components.Harddisk import harddiskmanager
from Components.UsageConfig import preferredTimerPath, preferredInstantRecordPath, defaultMoviePath, defaultStorageDevice
from Components.EpgList import EPGList, Rect, EPG_TYPE_SINGLE, EPG_TYPE_SIMILAR, EPG_TYPE_MULTI
from Components.Sources.ServiceEvent import ServiceEvent
from Screens.MessageBox import MessageBox
from Screens.ChoiceBox import ChoiceBox
from Screens.TimerSelection import TimerSelection
from Screens.TimeDateInput import TimeDateInput
from Screens.InputBox import InputBox
from Components.Pixmap import Pixmap
from Components.Button import Button
from Components.Label import Label
from Components.ScrollLabel import ScrollLabel
from Components.ActionMap import ActionMap, HelpableActionMap
from Components.Sources.Event import Event
from ServiceReference import ServiceReference
from enigma import eServiceReference, eServiceCenter, eTimer, eEPGCache, getDesktop
from time import localtime, time, mktime, strftime
from Components.config import config, ConfigSubsection, ConfigSelection, ConfigClock, ConfigInteger, ConfigSelection, ConfigYesNo, getConfigListEntry, ConfigBoolean
from Components.ConfigList import ConfigListScreen
from Tools.Directories import resolveFilename, fileExists
from Tools.BoundFunction import boundFunction  

from time import time, localtime, strftime  
from os import path as os_path

yes_no_descriptions = {False: _("no"), True: _("yes")}      
config.plugins.instantepgtimer = ConfigSubsection() 
stopopt=[]
stopopt.append(( "yes", _("Select") + " " + _("Recording")))  
stopopt.append(( "no",_("Ask user")))  
stopopt.append(( "ok",_("auto") + " " + _("stop recording")))  
config.plugins.instantepgtimer.stop = ConfigSelection(default="yes", choices = stopopt)
deleteopt=[]
deleteopt.append(( "yes",_("Ask user") ))  
deleteopt.append(( "no",_("no") ))  
deleteopt.append(( "ok",_("auto") + " " + _("Recording")+" "+_("delete file") ))
config.plugins.instantepgtimer.delete = ConfigSelection(default="no", choices = deleteopt)
startmenu=[]
startmenu.append(( "yes",_("yes") ))  
startmenu.append(( "event",_("add recording (stop after current event)") ))
startmenu.append(( "indefinitely",_("add recording (indefinitely)") ))
startmenu.append(( "manualduration",_("add recording (enter recording duration)") ))
startmenu.append(( "manualendtime",_("add recording (enter recording endtime)") ))
if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/PermanentTimeshift"):
	startmenu.append(( "savetimeshift",_("Timeshift")+" "+_("save recording (stop after current event)") ))
	startmenu.append(( "savetimeshiftEvent",_("Timeshift")+" "+_("save recording (Select event)") ))
startmenu.append(( "no",_("don't record") ))
config.plugins.instantepgtimer.startmenu = ConfigSelection(default="yes", choices = startmenu)
stopmenu=[]
stopmenu.append(( "yes",_("yes") ))  
stopmenu.append(( "stop",_("stop recording") ))
stopmenu.append(( "event",_("add recording (stop after current event)") ))
stopmenu.append(( "indefinitely",_("add recording (indefinitely)") ))
stopmenu.append(( "manualduration",_("add recording (enter recording duration)") ))
stopmenu.append(( "manualendtime",_("add recording (enter recording endtime)") ))
stopmenu.append(( "changeduration",_("change recording (duration)") ))
stopmenu.append(( "changeendtime",_("change recording (endtime)") ))
if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/PermanentTimeshift"):
	stopmenu.append(( "savetimeshift",_("Timeshift")+" "+_("save recording (stop after current event)") ))
	stopmenu.append(( "savetimeshiftEvent",_("Timeshift")+" "+_("save recording (Select event)") ))
stopmenu.append(( "no",_("do nothing") ))
config.plugins.instantepgtimer.stopmenu = ConfigSelection(default="yes", choices = stopmenu)
config.plugins.instantepgtimer.length = ConfigInteger(default=5, limits=(0,240))
config.plugins.instantepgtimer.loadepg = ConfigBoolean(default = False, descriptions=yes_no_descriptions)
config.plugins.instantepgtimer.extensions = ConfigBoolean(default = False, descriptions=yes_no_descriptions)
config.plugins.instantepgtimer.channels = ConfigBoolean(default = False, descriptions=yes_no_descriptions)
config.plugins.instantepgtimer.infodirect = ConfigBoolean(default = False, descriptions=yes_no_descriptions)

YELLOWC =  '\033[33m'                                                           
ENDC = '\033[m'                                                                 
                                                                                
def cprint(text):                                                               
        print(YELLOWC+"[InstantEpgTimer] "+text+ENDC)     

EPGSearch_self=None

try:
	# try to remember original from EPGSearch  (audio-key + blue-key)
	import Plugins.Extensions.EPGSearch.EPGSearch as EPGSearch
	#EPGSelection_ori__init__= EPGSearch.EPGSelection__init__
	EPGSearch_ori__init__= EPGSearch.EPGSearch.__init__
except:
	# remember original
	pass

EPGSelection_ori__init__= Screens.EpgSelection.EPGSelection.__init__
EPGSelection_ori_removeTimer= Screens.EpgSelection.EPGSelection.removeTimer

def EPGSearch__init__(self, session, *args, **kwargs):
	cprint(">>>> EPGSearch.__init__")
	EPGSearch_ori__init__(self, session, *args, **kwargs)
	global EPGSearch_self
	EPGSearch_self = self
	self.searchargs=args
	self.searchkwargs=kwargs
	self.instantepgtimer_searchargs = self.searchargs
	self.instantepgtimer_searchkwargs = self.searchkwargs
	# print("== init searchargs",self.searchargs)
	self["instandRecordActions"] = ActionMap(["InfobarInstantRecord"],
		{
		"instantRecord":        self.instantRecord,
		}, -1)

def EPGSelection__init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None, serviceChangeCB=None):
	cprint(">>>> EPGSelection.__init__")
	EPGSelection_ori__init__(self, session, service, zapFunc, eventid, bouquetChangeCB, serviceChangeCB)
	self["instandRecordActions"] = ActionMap(["InfobarInstantRecord"],
		{
		"instantRecord":        self.instantRecord,
		}, -1)
	
#	serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
#	s1=serviceref.toString()
#	s2=service.toString()
#	if config.plugins.instantepgtimer.infodirect.value and s1 != s2:
#		self.InfoTimer = eTimer()                                      
#		self.InfoTimer_conn = self.InfoTimer.timeout.connect(self.doInfo)
#		self.InfoTimer.start(50, True)                                
                                                                                     
#def EPGSelection_doInfo(self):                                                              
#	self.InfoTimer.stop()                                                  
#	self.infoKeyPressed()
#	self.close()

def EPGSelection_instantRecord(self):
	cprint(">>>> EPGSelection.instantRecord")

	#==== set searchargs for reload EPGSearchlist after setTimer=====
	global EPGSearch_self
	try: #only if EPGSearch is open
		searchargs_list=list(EPGSearch_self.instantepgtimer_searchargs)
		searchargs_list[0] = EPGSearch_self.currSearch
		searchargs=tuple(searchargs_list)
		self.searchargs= searchargs
	except:
		pass
	#================================================================

	cur = self["list"].getCurrent()
	event = cur[0]
	serviceref = cur[1]
	if event is None:
		return
	eventid = event.getEventId()
	refstr = serviceref.ref.toString()
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
			cb_func = lambda ret : not ret or self.removeTimer(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
			break
	else:
		newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(event))
#		self.session.nav.RecordTimer.saveTimer()    
		if self.type == EPG_TYPE_MULTI:
			self["list"].updateMultiEPG(0)
		else:
			# bad fix, I know ...
			try:
				self.searchargs=self.instantepgtimer_searchargs
			except:
				pass
			try:
				self.searchkwargs=self.instantepgtimer_searchkwargs
			except:
				pass
			self.onCreate()
		self.finishedAdd((True,newEntry))

def EPGSelection_removeTimer(self, timer):    
	cprint(">>>> EPGSelection.removeTimer")
	EPGSelection_ori_removeTimer(self, timer)
        if config.plugins.instantepgtimer.delete.value != "no":
              	self.deleteRecording(timer)  

def EPGSelection_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			try:
	                	if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:                             
					self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
				else:
					self.deleteRecordingConfirmed(service,True)
			except:
	                	if config.plugins.instantepgtimer.delete.value == "yes":                             
					self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
				else:
					self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def EPGSelection_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

try:
	# try to remember original from EPGSearch (audio-key)
	import Plugins.Extensions.EPGSearch.EPGSearch as EPGSearch
	EventViewBase_ori__init__=EPGSearch.EventViewBase__init__
except:
	# remember original
	EventViewBase_ori__init__=Screens.EventView.EventViewBase.__init__

def EventViewBase__init__(self, Event, Ref, callback=None, similarEPGCB=None):
	cprint(">>>> EventViewBase.__init__")
	EventViewBase_ori__init__(self, Event, Ref, callback, similarEPGCB)
	self["instandRecordActions"] = ActionMap(["InfobarInstantRecord"],
		{
		"instantRecord":        self.instantRecord,
		}, -1)

def EventViewBase_instantRecord(self):
	cprint(">>>> EventViewBase.instantRecord")
	if self.isRecording:
		return
	event = self.event
	serviceref = self.currentService
	if event is None:
		return
	eventid = event.getEventId()
	refstr = serviceref.ref.toString()
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
			cb_func = lambda ret : not ret or self.removeTimer(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
			break
	else:
		newEntry = RecordTimerEntry(self.currentService, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(self.event))
#		self.session.nav.RecordTimer.saveTimer()  
		self.onCreate()
		self.finishedAdd((True,newEntry))

EventViewBase_ori_removeTimer=Screens.EventView.EventViewBase.removeTimer
def EventViewBase_removeTimer(self, timer):
	cprint(">>>> EventViewBase.removeTimer")
	EventViewBase_ori_removeTimer(self, timer)
	if config.plugins.instantepgtimer.delete.value != "no":
		self.deleteRecording(timer)

def EventViewBase_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
	                if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:                             
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def EventViewBase_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

def InfoBarInstantRecord__init__(self):     
	cprint(">>>> InfoBarInstantRecord.__init__")
	"""Instant Record - handles the instantRecord action in order to
	start/stop instant records"""
	self.force_menu=False
	self["InstantRecordActions"] = HelpableActionMap(self, "InfobarInstantRecord",
		{
			"instantRecord": (self.instantRecord, _("Instant Record...")),
		})

	self.session.nav.RecordTimer.on_state_change.append(self.timerentryOnStateChange)

	# remember for direct usage from extensions menu ...
	Screens.InfoBarGenerics.InfoBarInstantRecord.instance=self

	self.recording = []

	self.stopOptionList = ((_("stop recording"), "stop"), \
		(_("add recording (stop after current event)"), "event"), \
		(_("add recording (indefinitely)"), "indefinitely"), \
		(_("add recording (enter recording duration)"), "manualduration"), \
		(_("add recording (enter recording endtime)"), "manualendtime"), \
		(_("change recording (duration)"), "changeduration"), \
		(_("change recording (endtime)"), "changeendtime"), \
		(_("do nothing"), "no"))

	self.startOptionList = ((_("add recording (stop after current event)"), "event"), \
		(_("add recording (indefinitely)"), "indefinitely"), \
		(_("add recording (enter recording duration)"), "manualduration"), \
		(_("add recording (enter recording endtime)"), "manualendtime"), \
		(_("don't record"), "no"))

def InfoBarInstantRecord_startInstantRecording(self, limitEvent = False, serviceref = None):
	if serviceref is None:
		serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
	cprint("starts Instant Recording %s ..."  % serviceref.toString())

	# try to get event info
	event = None
	try:
		epg = eEPGCache.getInstance()
		event = epg.lookupEventTime(serviceref, -1, 0)
		if event is None:
			info = eServiceCenter.getInstance().info(serviceref) 
#			info = service.info()
			ev = info.getEvent(0)
			event = ev
	except:
		pass

	begin = int(time.time())
	end = begin + 3600	# dummy
	name = "instant record"
	description = ""
	eventid = None

	if event is not None:
		curEvent = parseEvent(event)
		name = curEvent[2]
		description = curEvent[3]
		eventid = curEvent[4]
		if limitEvent:
			end = curEvent[1]
	else:
		if limitEvent:
			self.session.open(MessageBox, _("No event info found, recording indefinitely."), MessageBox.TYPE_INFO, is_dialog=False)

	if isinstance(serviceref, eServiceReference):
		serviceref = ServiceReference(serviceref)

	recording = RecordTimerEntry(serviceref, begin, end, name, description, eventid, dirname = preferredInstantRecordPath())

#	why do I have to remove this at all ...
#	recording.dontSave = True

	if event is None or limitEvent == False:
		recording.autoincrease = True
		recording.setAutoincreaseEnd()

	self.recording.append(recording)
	simulTimerList = self.session.nav.RecordTimer.record(recording)

	if simulTimerList is not None:
		if len(simulTimerList) > 1: # with other recording
			name = simulTimerList[1].name
			name_date = ' '.join((name, strftime('%c', localtime(simulTimerList[1].begin))))
			cprint("conflicts with %s" % name_date)
			recording.autoincrease = True	# start with max available length, then increment
			if recording.setAutoincreaseEnd():
				self.session.nav.RecordTimer.record(recording)
				self.session.open(MessageBox, _("Record time limited due to conflicting timer %s") % name_date, MessageBox.TYPE_INFO, is_dialog=False)
			else:
				self.recording.remove(recording)
				self.session.open(MessageBox, _("Couldn't record due to conflicting timer %s") % name, MessageBox.TYPE_INFO, is_dialog=False)
		else:
			self.recording.remove(recording)
			self.session.open(MessageBox, _("Couldn't record due to invalid service %s") % serviceref, MessageBox.TYPE_INFO, is_dialog=False)
		recording.autoincrease = False

def InfoBarInstantRecord_isInstantRecordRunning(self, eventid=None):
	cprint(">>>> InfoBarInstantRecord self.recording: %s" %self.recording)
	cur = self.session.nav.getCurrentlyPlayingServiceReference()
	#self.recording = self.session.nav.RecordTimer.timer_list #all timer
	if self.recording:
		for x in self.recording:
			# True only when selected Channel ...
			if x.isRunning() and x.service_ref.ref.toString() == cur.toString():
				#cprint("=== timer: %s %s %s" % (x.name, x.eit, eventid))
				if eventid is not None:
					if x.eit == eventid:
						return True
				else:
					return True
	return False

def InfoBarInstantRecord_instantRecord(self, force_menu=False):
	cprint(">>>> InfoBarInstantRecord_instantRecord force_menu: %s" % force_menu)
	self.force_menu=force_menu
	dir = preferredInstantRecordPath()
	if not dir or not fileExists(dir, 'w'):
		dir = defaultMoviePath()
	if not harddiskmanager.inside_mountpoint(dir):
		if harddiskmanager.HDDCount() and not harddiskmanager.HDDEnabledCount():
			self.session.open(MessageBox, _("Unconfigured storage devices found!") + "\n" \
				+ _("Please make sure to set up your storage devices with the storage management in menu -> setup -> system -> storage devices."), MessageBox.TYPE_ERROR, is_dialog=False)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() == "<undefined>":
			self.session.open(MessageBox, _("No default storage device found!") + "\n" \
				+ _("Please make sure to set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR, is_dialog=False)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() != "<undefined>":
			part = harddiskmanager.getDefaultStorageDevicebyUUID(defaultStorageDevice())
			if part is None:
				self.session.open(MessageBox, _("Default storage device is not available!") + "\n" \
					+ _("Please verify if your default storage device is attached or set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR, is_dialog=False)
				return
		else:
			# XXX: this message is a little odd as we might be recording to a remote device
			self.session.open(MessageBox, _("No HDD found or HDD not initialized!"), MessageBox.TYPE_ERROR, is_dialog=False)
			return

	#==== get current eventid ===================
	cur = self.session.nav.getCurrentlyPlayingServiceReference()
	self.curEvent = getEvent(cur)
	eventid = None
	if self.curEvent is not None:
		eventid = self.curEvent[4]
	#==== ende get current eventid ==============
	
	if config.plugins.instantepgtimer.stopmenu.value == "yes" or self.force_menu:
		eventid = None

	print("=== isInstantRecordRunning", self.isInstantRecordRunning)
	if self.isInstantRecordRunning(eventid):
		if config.plugins.instantepgtimer.stopmenu.value == "yes" or self.force_menu:
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("A recording is currently running.\nWhat do you want to do?"), \
				list=self.stopOptionList, is_dialog=False)
		else:
			self.recordQuestionCallback((_("stop recording"), config.plugins.instantepgtimer.stopmenu.value))
	else:
		if config.plugins.instantepgtimer.startmenu.value == "yes" or self.force_menu:
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("Start recording?"), \
				list=self.startOptionList, is_dialog=False)
		else:
			self.recordQuestionCallback(("add recording", config.plugins.instantepgtimer.startmenu.value))

def InfoBarInstantRecord_recordQuestionCallback(self, answer):
	cprint("pre:\n%s" % self.recording)

	if answer is None or answer[1] == "no":
		return
	cur = self.session.nav.getCurrentlyPlayingServiceReference()
	list = []
	recording = self.recording[:]
	timer=None
	for x in recording:
		if not x in self.session.nav.RecordTimer.timer_list or not x.isRunning(): # check for isRunning because of repeated timer (there are still in the timerlist!)
			self.recording.remove(x)
		elif x.isRunning():
			if x.service_ref.ref.toString() == cur.toString():
				timer=x
			list.append((x, False))

	if answer[1] == "changeduration":
		self.session.openWithCallback(self.changeDuration, TimerSelection, list)
	elif answer[1] == "changeendtime":
		self.session.openWithCallback(self.setEndtime, TimerSelection, list)
	elif answer[1] == "stop":
		if config.plugins.instantepgtimer.stop.value == "yes":
			self.session.openWithCallback(self.stopCurrentRecording, TimerSelection, list)
		else:
			if timer is not None:
				cb_func = lambda ret : not ret or self.removeTimer(timer)
				if config.plugins.instantepgtimer.stop.value == "ok":
					cb_func(True)
				else:
					self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % timer.name)
	elif answer[1] in ( "indefinitely" , "manualduration", "manualendtime", "event"):
		self.startInstantRecording(limitEvent = answer[1] in ("event", "manualendtime") or False)
		if answer[1] == "manualduration":
			self.changeDuration(len(self.recording)-1)
		elif answer[1] == "manualendtime":
			self.setEndtime(len(self.recording)-1)
	cprint("after:\n%s" % self.recording)

def InfoBarInstantRecord_stopCurrentRecording(self, entry = -1):
	if entry is not None and entry != -1:
		t = self.recording[entry]
		if t.repeated:	# do not delete repeated timer, ask user what to do
			choicelist = (
				(_("Stop current event but not coming events"), "stoponlycurrent"),
				(_("Stop current event and disable coming events"), "stopall")
			)
			self.session.openWithCallback(boundFunction(self.runningRepeatedTimerCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = choicelist, is_dialog=False)
		else:
			self.session.nav.RecordTimer.removeEntry(t)
			self.recording.remove(t)
	                if config.plugins.instantepgtimer.delete.value != "no" or self.force_menu:                             
	                	self.deleteRecording(t)  

def InfoBarInstantRecord_runningRepeatedTimerCallback(self, t, result):
	if result is not None:
		if result[1] == "stoponlycurrent":
			t.enable()
			t.processRepeated(findRunningEvent = False)
			self.session.nav.RecordTimer.doActivate(t)
		elif result[1] == "stopall":
			t.disable()
		self.session.nav.RecordTimer.timeChanged(t)
		self.recording.remove(t)
                if config.plugins.instantepgtimer.delete.value != "no" or self.force_menu:                             
                	self.deleteRecording(t)  

def InfoBarInstantRecord_removeTimer(self, timer):
	if timer is not None:
		timer.afterEvent = AFTEREVENT.NONE
		self.session.nav.RecordTimer.removeEntry(timer)
                self.recording.remove(timer)                        
                if config.plugins.instantepgtimer.delete.value != "no" or self.force_menu:                             
                	self.deleteRecording(timer)  

def InfoBarInstantRecord_changeDuration(self, entry):
	if entry is not None and entry >= 0:
		self.selectedEntry = entry
		self.session.openWithCallback(self.inputCallback, InputBox, title=_("How many minutes do you want to record?"), text=str(config.plugins.instantepgtimer.length.value), maxSize=False, type=Input.NUMBER, is_dialog=False)

def InfoBarInstantRecord_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
	                if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:                             
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def InfoBarInstantRecord_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

# remember original
InfoBarEPG_ori__init__=Screens.InfoBarGenerics.InfoBarEPG.__init__
InfoBarEPG_ori_openEventView=Screens.InfoBarGenerics.InfoBarEPG.openEventView

def InfoBarEPG__init__(self):
	# remember for direct usage from extensions menu ...
	Screens.InfoBarGenerics.InfoBarEPG.instance=self
	InfoBarEPG_ori__init__(self)

def InfoBarEPG_showEventInfoPlugins(self, force_menu=False):
	cprint(">>>> InfoBarEPG.showEventInfoPlugins")
	plist=[]
	plist.append((_("show EPG..."), self.openEventViewOri))
	for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EVENTINFO):
		plist.append((p.name, boundFunction(self.runPlugin,p)))
	plist.append((_("show single service EPG..."), self.openSingleServiceEPG))
	if config.misc.epgcache_outdated_timespan.value:
		plist.append((_("show outdated service EPG..."), self.openOutdatedSingleServiceEPG))
	plist.append((_("Multi EPG"), self.openMultiServiceEPG))
	if config.plugins.instantepgtimer.infolong.value == "0" or force_menu:
		self.session.openWithCallback(self.EventInfoPluginChosen, ChoiceBox, title=_("Please choose an extension..."), list = plist, skin_name = "EPGExtensionsList", is_dialog=False)
	else:
		i=int(config.plugins.instantepgtimer.infolong.value)-2  
		ll=len(plist)-1
		if i > ll:
			i=ll
		if i < 0:
			i=0
		cprint("starts %d from %s" %(i,plist[i][0]))
		plist[i][1]()

def InfoBarEPG_openEventView(self, force_menu=False):
	cprint(">>>> InfoBarEPG.openEventView")
	plist=[]
	plist.append((_("show EPG..."), self.openEventViewOri))
	for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EVENTINFO):
		plist.append((p.name, boundFunction(self.runPlugin,p)))
	plist.append((_("show single service EPG..."), self.openSingleServiceEPG))
	if config.misc.epgcache_outdated_timespan.value:
		plist.append((_("show outdated service EPG..."), self.openOutdatedSingleServiceEPG))
	plist.append((_("Multi EPG"), self.openMultiServiceEPG))
	if config.plugins.instantepgtimer.infoshort.value == "0" or force_menu:
		self.session.openWithCallback(self.EventInfoPluginChosen, ChoiceBox, title=_("Please choose an extension..."), list = plist, skin_name = "EPGExtensionsList", is_dialog=False)
	else:
		i=int(config.plugins.instantepgtimer.infoshort.value)-2
		ll=len(plist)-1
		if i > ll:
			i=ll
		if i < 0:
			i=0
		cprint("starts %d from %s" %(i,plist[i][0]))
		plist[i][1]()

# if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/PiPChannelSelection"):
	# from Plugins.Extensions.PiPChannelSelection.PiPChannelSelection import ChannelSelectionBase__init__ as PCS_ChannelSelectionBase__init__
	# ChannelSelectionBase_ori__init__ = PCS_ChannelSelectionBase__init__
# else:
	# # remember original __init__
	# ChannelSelectionBase_ori__init__= Screens.ChannelSelection.ChannelSelectionBase.__init__
	
ChannelSelectionBase_ori__init__ = None

def ChannelSelectionBase__init__(self, session):     
	cprint(">>>> ChannelSelectionBase.__init__")
	# prevent PipZap Crash
	self.dopipzap = False                                                   
	self.enable_pipzap = False     
	#
	ChannelSelectionBase_ori__init__(self, session)     
	"""Instant Record - handles the instantRecord action in order to
	start/stop instant records"""
	self.force_menu=False
	
	#def searchEPG():
	#	cprint("== searchEPG")
	#	self.curEvent = getEvent(cur = self.servicelist.getCurrent())
	#	if self.curEvent is not None:
	#		name = self.curEvent[2]
	#	else:
	#		name = ''
	#	from Plugins.Extensions.EPGSearch.EPGSearch import EPGSearch
	#	self.session.open(EPGSearch, name, False)
	#	cprint("== openEPGSearch %s" % name)

	self["InstantRecordActions"] = HelpableActionMap(self, "InfobarInstantRecord",
		{
			"instantRecord": (self.instantRecord, _("Instant Record...")),
		})
	
	#self["actions7"] = HelpableActionMap(self, "InfobarAudioSelectionActions",
	#		{
	#			"audioSelection":  (searchEPG, _("Search EPG with Message")),
	#	})

	self.session.nav.RecordTimer.on_state_change.append(self.timerentryOnStateChange)
	self.recording = []

	self.stopOptionList = ((_("stop recording"), "stop"), \
		(_("add recording (stop after current event)"), "event"), \
		(_("add recording (indefinitely)"), "indefinitely"), \
		(_("add recording (enter recording duration)"), "manualduration"), \
		(_("add recording (enter recording endtime)"), "manualendtime"), \
		(_("change recording (duration)"), "changeduration"), \
		(_("change recording (endtime)"), "changeendtime"), \
		(_("do nothing"), "no"))

	self.startOptionList = ((_("add recording (stop after current event)"), "event"), \
		(_("add recording (indefinitely)"), "indefinitely"), \
		(_("add recording (enter recording duration)"), "manualduration"), \
		(_("add recording (enter recording endtime)"), "manualendtime"), \
		(_("don't record"), "no"))

def ChannelSelectionBase_timerentryOnStateChange(self, timer):
	# timer recording has been started, append to self.recording list
	if hasattr(self, "recording") and timer.isRunning():
		if not timer in self.recording: # only if timer is not in list already
			self.recording.append(timer)

def ChannelSelectionBase_stopCurrentRecording(self, entry = -1):
	if entry is not None and entry != -1:
		t = self.recording[entry]
		if t.repeated:	# do not delete repeated timer, ask user what to do
			choicelist = (
				(_("Stop current event but not coming events"), "stoponlycurrent"),
				(_("Stop current event and disable coming events"), "stopall")
			)
			self.session.openWithCallback(boundFunction(self.runningRepeatedTimerCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = choicelist)
		else:
			self.session.nav.RecordTimer.removeEntry(t)
			self.recording.remove(t)
	                if config.plugins.instantepgtimer.delete.value != "no" or self.force_menu:                             
	                	self.deleteRecording(t)  

def ChannelSelectionBase_runningRepeatedTimerCallback(self, t, result):
	if result is not None:
		if result[1] == "stoponlycurrent":
			t.enable()
			t.processRepeated(findRunningEvent = False)
			self.session.nav.RecordTimer.doActivate(t)
		elif result[1] == "stopall":
			t.disable()
		self.session.nav.RecordTimer.timeChanged(t)
		self.recording.remove(t)
                if config.plugins.instantepgtimer.delete.value != "no" or self.force_menu:                             
                	self.deleteRecording(t)  

def ChannelSelectionBase_startInstantRecording(self, limitEvent = False):
	cur = self.servicelist.getCurrent()
	if cur.flags & eServiceReference.isMarker: 
		cprint("MARKER")
		return
	if cur.flags & eServiceReference.mustDescent: 
		cprint("BOUQUET") # bouquet or service with alternatives
		return
	serviceref = cur

	begin = int(time())
	end = begin + 3600	# dummy
	name = "instant record"
	description = ""
	eventid = None

	#==== get eventdata ===================
	if self.curEvent is not None:
		name = self.curEvent[2]
		description = self.curEvent[3]
		eventid = self.curEvent[4]
		if limitEvent:
			end = self.curEvent[1]
	else:
		if limitEvent:
			self.session.open(MessageBox, _("No event info found, recording indefinitely."), MessageBox.TYPE_INFO, is_dialog=False)

	if isinstance(serviceref, eServiceReference):
		serviceref = ServiceReference(serviceref)

	recording = RecordTimerEntry(serviceref, begin, end, name, description, eventid, dirname = preferredInstantRecordPath())

#	why do I have to remove this at all ...
#	recording.dontSave = True

	if self.curEvent is None or limitEvent == False:
		recording.autoincrease = True
		recording.setAutoincreaseEnd()

	self.recording.append(recording)
	simulTimerList = self.session.nav.RecordTimer.record(recording)

	if simulTimerList is not None:
		if len(simulTimerList) > 1: # with other recording
			name = simulTimerList[1].name
			name_date = ' '.join((name, strftime('%c', localtime(simulTimerList[1].begin))))
			cprint("TIMER conflicts with %s" % name_date)
			recording.autoincrease = True	# start with max available length, then increment
			if recording.setAutoincreaseEnd():
				self.session.nav.RecordTimer.record(recording)
				self.session.open(MessageBox, _("Record time limited due to conflicting timer %s") % name_date, MessageBox.TYPE_INFO)
			else:
				self.recording.remove(recording)
				self.session.open(MessageBox, _("Couldn't record due to conflicting timer %s") % name, MessageBox.TYPE_INFO)
		else:
			self.recording.remove(recording)
			self.session.open(MessageBox, _("Couldn't record due to invalid service %s") % serviceref, MessageBox.TYPE_INFO)
		recording.autoincrease = False

def ChannelSelectionBase_recordQuestionCallback(self, answer):
	cprint("pre:\n%s" % self.recording)

	if answer is None or answer[1] == "no":
		return
	cur = self.servicelist.getCurrent()
	
	#==== get eventid ===================
	eventid=None
	if self.curEvent is not None:
		eventid = self.curEvent[4]
	
	list = []
	recording = self.recording[:]
	timer=None
	for x in recording:
		if not x in self.session.nav.RecordTimer.timer_list or not x.isRunning(): # check for isRunning because of repeated timer (there are still in the timerlist!)
			self.recording.remove(x)
		elif x.isRunning():
			if x.service_ref.ref.toString() == cur.toString():
				if x.eit == eventid and config.plugins.instantepgtimer.stop.value != "yes":
					#cprint("=== timer gefunden %s %s %s" % (x.name, x.eit, eventid))
					timer=x
					break
				if timer is None or x.begin < timer.begin:
					timer=x
				#cprint("=== timer.eitx %s name %s eventid %s" % (x.eit, x.name, eventid))
			list.append((x, False))

	if answer[1] == "changeduration":
		self.session.openWithCallback(self.changeDuration, TimerSelection, list)
	elif answer[1] == "changeendtime":
		self.session.openWithCallback(self.setEndtime, TimerSelection, list)
	elif answer[1] == "stop":
		if config.plugins.instantepgtimer.stop.value == "yes":
			self.session.openWithCallback(self.stopCurrentRecording, TimerSelection, list)
		else:
			if timer is not None:
				cb_func = lambda ret : not ret or self.removeTimer(timer)
				if config.plugins.instantepgtimer.stop.value == "ok":
					cb_func(True)
				else:
					self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % timer.name)
	elif answer[1] in ( "indefinitely" , "manualduration", "manualendtime", "event"):
		self.startInstantRecording(limitEvent = answer[1] in ("event", "manualendtime") or False)
		if answer[1] == "manualduration":
			self.changeDuration(len(self.recording)-1)
		elif answer[1] == "manualendtime":
			self.setEndtime(len(self.recording)-1)
	cprint("after:\n%s" % self.recording)
	self.servicelist.l.invalidate()

def ChannelSelectionBase_setEndtime(self, entry):
	if entry is not None and entry >= 0:
		self.selectedEntry = entry
		self.endtime=ConfigClock(default = self.recording[self.selectedEntry].end)
		dlg = self.session.openWithCallback(self.TimeDateInputClosed, TimeDateInput, self.endtime)
		dlg.setTitle(_("Please change recording endtime"))

def ChannelSelectionBase_TimeDateInputClosed(self, ret):
	if len(ret) > 1:
		if ret[0]:
			localendtime = localtime(ret[1])
			cprint("stopping recording at %s" % strftime("%c", localendtime))
			if self.recording[self.selectedEntry].end != ret[1]:
				self.recording[self.selectedEntry].autoincrease = False
			self.recording[self.selectedEntry].end = ret[1]
			self.session.nav.RecordTimer.timeChanged(self.recording[self.selectedEntry])

def ChannelSelectionBase_changeDuration(self, entry):
	if entry is not None and entry >= 0:
		self.selectedEntry = entry
		self.session.openWithCallback(self.inputCallback, InputBox, title=_("How many minutes do you want to record?"), text=str(config.plugins.instantepgtimer.length.value), maxSize=False, type=Input.NUMBER)

def ChannelSelectionBase_inputCallback(self, value):
	if value is not None:
		cprint("stopping recording after %d minutes" % int(value))
		entry = self.recording[self.selectedEntry]
		if int(value) != 0:
			entry.autoincrease = False
		entry.end = int(time()) + 60 * int(value)
		self.session.nav.RecordTimer.timeChanged(entry)

def ChannelSelectionBase_removeTimer(self, timer):
	if timer is not None:
		timer.afterEvent = AFTEREVENT.NONE
		self.session.nav.RecordTimer.removeEntry(timer)
		self.recording.remove(timer)                        
		if config.plugins.instantepgtimer.delete.value != "no":                             
			self.deleteRecording(timer)
		self.servicelist.l.invalidate()

def ChannelSelectionBase_isInstantRecordRunning(self, eventid=None):
	cprint("self.recording %s" % self.recording)
	cur = self.servicelist.getCurrent()
	#self.recording = self.session.nav.RecordTimer.timer_list #all timer
	if self.recording:
		for x in self.recording:
			# True only when selected Channel ...
			if x.isRunning() and x.service_ref.ref.toString() == cur.toString():
				#cprint("=== timer: %s %s %s" % (x.name, x.eit, eventid))
				if eventid is not None:
					if x.eit == eventid:
						return True
				else:
					return True
	return False

def ChannelSelectionBase_instantRecord(self):
	cur = self.servicelist.getCurrent()
	if cur.flags & eServiceReference.isMarker: 
		cprint("MARKER")
		return
	if cur.flags & eServiceReference.mustDescent: 
		cprint("BOUQUET") # bouquet or service with alternatives
		return
	dir = preferredInstantRecordPath()
	if not dir or not fileExists(dir, 'w'):
		dir = defaultMoviePath()
	if not harddiskmanager.inside_mountpoint(dir):
		if harddiskmanager.HDDCount() and not harddiskmanager.HDDEnabledCount():
			self.session.open(MessageBox, _("Unconfigured storage devices found!") + "\n" \
				+ _("Please make sure to set up your storage devices with the storage management in menu -> setup -> system -> storage devices."), MessageBox.TYPE_ERROR)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() == "<undefined>":
			self.session.open(MessageBox, _("No default storage device found!") + "\n" \
				+ _("Please make sure to set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() != "<undefined>":
			part = harddiskmanager.getDefaultStorageDevicebyUUID(defaultStorageDevice())
			if part is None:
				self.session.open(MessageBox, _("Default storage device is not available!") + "\n" \
					+ _("Please verify if your default storage device is attached or set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR)
				return
		else:
			# XXX: this message is a little odd as we might be recording to a remote device
			self.session.open(MessageBox, _("No HDD found or HDD not initialized!"), MessageBox.TYPE_ERROR)
			return
	
	#==== get selected eventid ===================
	self.curEvent = getEvent(cur)
	eventid = None
	if self.curEvent is not None:
		eventid = self.curEvent[4]
	#==== ende get eventid ==============
	
	if config.plugins.instantepgtimer.stopmenu.value == "yes":
		eventid = None
	
	if self.isInstantRecordRunning(eventid):
		if config.plugins.instantepgtimer.stopmenu.value == "yes":
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("A recording is currently running.\nWhat do you want to do?"), \
				list=self.stopOptionList)
		else:
			self.recordQuestionCallback((_("stop recording"), config.plugins.instantepgtimer.stopmenu.value))
	else:
		if config.plugins.instantepgtimer.startmenu.value == "yes":
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("Start recording?"), \
				list=self.startOptionList)
		else:
			self.recordQuestionCallback(("add recording", config.plugins.instantepgtimer.startmenu.value))

def ChannelSelectionBase_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def ChannelSelectionBase_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

def getEvent(cur):
	#==== get eventid ===================
	serviceref = cur
	refstr = serviceref.toString()
	event = None
	try:
		epg = eEPGCache.getInstance()
		event = epg.lookupEventTime(serviceref, -1, 0)
		if event is None:
			info = eServiceCenter.getInstance().info(serviceref) 
			ev = info.getEvent(0)
			event = ev
	except:
		pass
	eventid = None
	if event is not None:
		curEvent = parseEvent(event)
		return curEvent
	else:
		return event
	#==== ende get eventid ==============

# remember original __init__
ChannelSelectionEPG_ori_showEPGList=Screens.ChannelSelection.ChannelSelectionEPG.showEPGList

def ChannelSelectionEPG_showEPGList(self):
	
	def openSimilarList(eventid, refstr):
		from Screens.EpgSelection import EPGSelection
		self.session.open(EPGSelection, refstr, None, eventid)
	
	def openSingleServiceEPG():
		from Screens.EpgSelection import EPGSelection
		#self.session.open(EPGSelection, self.getCurrentSelection(), serviceChangeCB = self.changeServiceCB)
		self.savedService = self.getCurrentSelection()
		self.session.openWithCallback(self.SingleServiceEPGClosed, EPGSelection, self.getCurrentSelection(), serviceChangeCB=self.changeServiceCB)

	def SingleServiceEPGClosed(ret=False):
		self.setCurrentSelection(self.savedService) 

	def eventViewCallback(setEvent, setService, val):
		selected_serviceref = self.getCurrentSelection()
		if val == -1:
			self.moveUp()
		elif val == +1:
			self.moveDown()
		selected_serviceref = self.getCurrentSelection()
		
		event = None
		try:
			epg = eEPGCache.getInstance()
			event = epg.lookupEventTime(selected_serviceref, -1, 0)
			if event is None:
				info = eServiceCenter.getInstance().info(selected_serviceref) 
				event = info.getEvent(0)
		except:
			pass

		if selected_serviceref:
			service = ServiceReference(selected_serviceref)
		setService(service)
		setEvent(event)
	
	selected_serviceref = self.getCurrentSelection()
	current_serviceref  = self.session.nav.getCurrentlyPlayingServiceReference()
	
	#s1=current_serviceref.toString()
	#s2=selected_serviceref.toString()
	#if config.plugins.instantepgtimer.infodirect.value and s1 != s2:
	if config.plugins.instantepgtimer.infodirect.value:
		event = None
		try:
			epg = eEPGCache.getInstance()
			event = epg.lookupEventTime(selected_serviceref, -1, 0)
			if event is None:
				info = eServiceCenter.getInstance().info(selected_serviceref) 
				event = info.getEvent(0)
		except:
			pass

		if selected_serviceref:
			service = ServiceReference(selected_serviceref)
		
		if event is not None:
			#from Screens.EventView import EventViewSimple
			from Screens.EventView import EventViewEPGSelect
			cprint("ChannelSelectionEPG_showEventViewSimple")
			#self.session.open(EventViewSimple, event, service, None, openSimilarList)
			#self.session.open(EventViewEPGSelect, event, service, None, openSingleServiceEPG, openMultiServiceEPG, openSimilarList)
			from Screens.InfoBar import InfoBar
			self.session.open(EventViewEPGSelect, event, service, eventViewCallback, openSingleServiceEPG, InfoBar.instance.openMultiServiceEPG, openSimilarList)
		
	else:
		cprint("ChannelSelectionEPG_ori_showEPGList")
		ChannelSelectionEPG_ori_showEPGList(self)

# remember original __init__
SelectionEventInfo_ori__init__=Screens.ChannelSelection.SelectionEventInfo.__init__

def SelectionEventInfo__init__(self):
	cprint(">>>> SelectionEventInfo.__init__")
	self.__service = None
	from API import session
	self.navcore = session.nav
	SelectionEventInfo_ori__init__(self)

def SelectionEventInfo_updateEventInfo(self):
	cprint(">>>> SelectionEventInfo.updateEventInfo")
	cur = self.getCurrentSelection()
	if config.plugins.instantepgtimer.loadepg.value:
		if cur.flags & eServiceReference.isMarker:
			cprint("MARKER")
			return
		if cur.flags & eServiceReference.mustDescent:
			cprint("BOUQUET") # bouquet or service with alternatives
			return
		serviceref = cur
		refstr = serviceref.toString()
		cprint(refstr)
		# try to get event info
		event = None
		try:
			epg = eEPGCache.getInstance()
			event = epg.lookupEventTime(serviceref, -1, 0)
			if event is None:
				info = eServiceCenter.getInstance().info(serviceref) 
				ev = info.getEvent(0)
				event = ev
		except:
			pass

		if event is None and refstr.startswith("1:0") and refstr.find("/") is -1:
			if self.__service is None:
				self.play(serviceref)
			else:
				# continue checking for EPG ...
				self.timer.start(300, True)
			return
		else:
			self.stopStreaming()
		self.timer.stop()
		self.servicelist.l.invalidate()
	self["ServiceEvent"].newService(cur)

def SelectionEventInfo_play(self, service):
	cprint(">>>> SelectionEventInfo.play")
	self.stopStreaming()
	self.__service = self.navcore.recordService(service)
	self.timer.stop()
	if self.__service is not None:
		self["ServiceEvent"].newService(None)
		self.__service.prepareStreaming()
		self.__service.start()
		# start checking for EPG ...
		self.timer.start(300, True)
		return True
	return False

def SelectionEventInfo_stopStreaming(self):
	cprint(">>>> SelectionEventInfo.stopStreaming")
	if self.__service is not None:
		self.navcore.stopRecordService(self.__service)
		self.__service = None

if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/GraphMultiEPG"):
	import Plugins.Extensions.GraphMultiEPG.GraphMultiEpg
	# remember original __init__
	GraphMultiEPG_ori__init__=Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.__init__
	GraphMultiEPG_ori_removeTimer=Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.removeTimer

def GraphMultiEPG__init__(self, session, services, zapFunc=None, bouquetChangeCB=None):
	cprint(">>>> GraphMultiEPG.__init__")
	GraphMultiEPG_ori__init__(self, session, services, zapFunc, bouquetChangeCB)
	self["instandRecordActions"] = ActionMap(["InfobarInstantRecord"],
		{
		"instantRecord":        self.instantRecord,
		}, -1)

def GraphMultiEPG_instantRecord(self):
	cprint(">>>> GraphMultiEPG.instantRecord")
	cur = self["list"].getCurrent()
	event = cur[0]
	serviceref = cur[1]
	if event is None:
		return
	eventid = event.getEventId()
	refstr = serviceref.ref.toString()
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
			cb_func = lambda ret : not ret or self.removeTimer(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
			break
	else:
		newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
		self["list"].fillMultiEPG(None) # refill
		self.finishedAdd((True,newEntry))

def GraphMultiEPG_removeTimer(self, timer):
		cprint(">>>> GraphMultiEPG_removeTimer")
		GraphMultiEPG_ori_removeTimer(self, timer)
		if config.plugins.instantepgtimer.delete.value != "no":                             
			self.deleteRecording(timer)  

def GraphMultiEPG_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def GraphMultiEPG_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPGCenter"):
	import Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter
	# remember original _deleteTimer
	MerlinEPGCenter_ori_deleteTimer=Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter.MerlinEPGCenter.deleteTimer
	
def MerlinEPGCenter_instantRecord(self):
	cprint(">>>> MerlinEPGCenter_instantRecord")
	cur = self["list"].getCurrent()
	if cur == None or cur[1] == None or cur[2] == "":
		return
			
	addTimer = True
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == cur[1] and timer.service_ref.ref.toString() == cur[2]:
			addTimer = False
			#self.deleteTimer(timer)
			#self.setButtonText(timerAdded = True)
			#self.getSimilarEvents()
			#self.setEventViewPicon(cur)
			eventName = ""
			eventName = cur[5]
			cb_func = lambda ret : not ret or self.deleteTimer(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % eventName)
			break
			
	if addTimer:
		# cur = ignoreMe, eventid, sRef, begin, duration, title, short, desc
		eit = cur[1]
		serviceref = ServiceReference(cur[2])
		begin = cur[3]
		end = cur[3] + cur[4]
		name = cur[5]
		description = cur[6]
		begin -= config.recording.margin_before.value * 60
		end += config.recording.margin_after.value * 60
		data = (begin, end, name, description, eit)

		newEntry=RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *data)
		#self.session.nav.RecordTimer.saveTimer()
		self.finishedAdd((True,newEntry))    
		# refresh the list
		self["timerlist"].moveToIndex(0)
		self["timerlist"].invalidate()
		self["list"].l.invalidate()
		self.updateState()
		self.onListSelectionChanged()

def MerlinEPGCenter_deleteTimer(self, timer):
	if timer is not None:
		MerlinEPGCenter_ori_deleteTimer(self, timer)
		self.setButtonText(timerAdded = True)
		self.getSimilarEvents()
		cur = self["list"].getCurrent()
		self.setEventViewPicon(cur)
		if config.plugins.instantepgtimer.delete.value != "no":                             
			self.deleteRecording(timer)  

def MerlinEPGCenter_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def MerlinEPGCenter_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/ValisEPG"):
	import Plugins.Extensions.ValisEPG.plugin
#	from Plugins.Extensions.ValisEPG.plugin import ValisEPG as ValisEPG
	# remember original _deleteTimer
	ValisEPG_ori_removeTimer=Plugins.Extensions.ValisEPG.plugin.ValisEPG.removeTimer

def ValisEPG_updateEventInfo(self):
		SelectionEventInfo_updateEventInfo(self)
		if self.aktListBox==1:
			#cur = self.getCurrentSelection()
			#self["ServiceEvent"].newService(cur)
			self.UpdateInfos()

def ValisEPG_instantRecord(self):
	self.updateEPGlist = False
	ref=self.getCurrentSelection()
	cur = self["epglist"].getCurrent()
	event = cur[0]
	if event is None:
		return
	serviceref = cur[1]
	eventid = event.getEventId()
	refstr = serviceref.ref.toString()
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
			cb_func = lambda ret : not ret or self.removeTimer(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
				#self.UpdateInfos()
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
			break
	else:
		newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(event))
		self.finishedAdd((True,newEntry))
		#self.UpdateInfos()
	self["epglist"].l.invalidate()
	self["list"].l.invalidate()

def ValisEPG_removeTimer(self, timer):
	ValisEPG_ori_removeTimer(self, timer)
	self["epglist"].l.invalidate()
	self["list"].l.invalidate()
	if config.plugins.instantepgtimer.delete.value != "no":
		self.deleteRecording(timer)  

def ValisEPG_deleteRecording(self, timer):
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def ValisEPG_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

# remember original __init__
#MovieSelection_ori__init__=Screens.MovieSelection.MovieSelection.__init__

MovieSelection_ori__init__ = None

def MovieSelection__init__(self, session, selectedmovie = None):
	cprint(">>>> MovieSelection.__init__")
	MovieSelection_ori__init__(self, session, selectedmovie)
	self["instandRecordActions"] = ActionMap(["InfobarInstantRecord"],
		{
		"instantRecord":        self.instantRecord,
		}, -1)

# for later usage ...
def MovieSelection_instantRecord(self):
	cprint(">>>> MovieSelection.instantRecord")
        current = self.getCurrent()                                     
        if current is not None:                                         
		cprint(current.toString())

def PTS_isInstantRecordRunning(self, eventid=None):
	cprint("PTS self.recording: %s" % self.recording)
	cur = self.session.nav.getCurrentlyPlayingServiceReference()
	#self.recording = self.session.nav.RecordTimer.timer_list #all timer
	if self.recording:
		for x in self.recording:
			# True only when selected Channel ...
			if x.isRunning() and x.service_ref.ref.toString() == cur.toString():
				#cprint("=== timer: %s %s %s" % (x.name, x.eit, eventid))
				if eventid is not None:
					if x.eit == eventid:
						return True
				else:
					return True
	return False
	
def PTS_instantRecord(self, force_menu=False):
	self.force_menu=force_menu
	cprint(">>>> InfoBar.instantRecord")
	if not config.plugins.pts.enabled.value or not self.timeshift_enabled:
		InfoBarInstantRecord_instantRecord(self, force_menu)
	#if not config.plugins.pts.enabled.value:
	#	InstantEPGTimer_InfoBarOrg.instantRecord(self)
		return

	dir = preferredInstantRecordPath()
	if not dir or not fileExists(dir, 'w'):
		dir = defaultMoviePath()

	if not harddiskmanager.inside_mountpoint(dir):
		if harddiskmanager.HDDCount() and not harddiskmanager.HDDEnabledCount():
			self.session.open(MessageBox, _("Unconfigured storage devices found!") + "\n" \
				+ _("Please make sure to set up your storage devices with the storage management in menu -> setup -> system -> storage devices."), MessageBox.TYPE_ERROR)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() == "<undefined>":
			self.session.open(MessageBox, _("No default storage device found!") + "\n" \
				+ _("Please make sure to set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR)
			return
		elif harddiskmanager.HDDEnabledCount() and defaultStorageDevice() != "<undefined>":
			part = harddiskmanager.getDefaultStorageDevicebyUUID(defaultStorageDevice())
			if part is None:
				self.session.open(MessageBox, _("Default storage device is not available!") + "\n" \
					+ _("Please verify if your default storage device is attached or set up your default storage device in menu -> setup -> system -> recording paths."), MessageBox.TYPE_ERROR)
				return
		else:
			# XXX: this message is a little odd as we might be recording to a remote device
			self.session.open(MessageBox, _("No HDD found or HDD not initialized!"), MessageBox.TYPE_ERROR)
			return
	
	#==== get current eventid ===================
	cur = self.session.nav.getCurrentlyPlayingServiceReference()
	self.curEvent = getEvent(cur)
	eventid = None
	if self.curEvent is not None:
		eventid = self.curEvent[4]
	#==== ende get current eventid ==============
	
	if config.plugins.instantepgtimer.stopmenu.value == "yes" or self.force_menu:
		eventid = None

	if self.isInstantRecordRunning(eventid): 
		if config.plugins.instantepgtimer.stopmenu.value == "yes" or self.force_menu:
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("A recording is currently running.\nWhat do you want to do?"), \
				list=((_("stop recording"), "stop"), \
				(_("add recording (stop after current event)"), "event"), \
				(_("add recording (indefinitely)"), "indefinitely"), \
				(_("add recording (enter recording duration)"), "manualduration"), \
				(_("add recording (enter recording endtime)"), "manualendtime"), \
				(_("change recording (duration)"), "changeduration"), \
				(_("change recording (endtime)"), "changeendtime"), \
				(_("Timeshift")+" "+_("save recording (stop after current event)"), "savetimeshift"), \
				(_("Timeshift")+" "+_("save recording (Select event)"), "savetimeshiftEvent"), \
				(_("do nothing"), "no")))
		else:
			if config.plugins.instantepgtimer.stop.value == "ok":
				# it is only a flag to reset, no recording to delete ...
				self.save_current_timeshift = False 
                                config.plugins.pts.isRecording.value = False
			self.recordQuestionCallback((_("stop recording"), config.plugins.instantepgtimer.stopmenu.value))
	else:
		if config.plugins.instantepgtimer.startmenu.value == "yes" or self.force_menu:
			self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
				title=_("Start recording?"), \
				list=((_("add recording (stop after current event)"), "event"), \
				(_("add recording (indefinitely)"), "indefinitely"), \
				(_("add recording (enter recording duration)"), "manualduration"), \
				(_("add recording (enter recording endtime)"), "manualendtime"), \
				(_("Timeshift")+" "+_("save recording (stop after current event)"), "savetimeshift"), \
				(_("Timeshift")+" "+_("save recording (Select event)"), "savetimeshiftEvent"), \
				(_("don't record"), "no")))
		else:
			if config.plugins.instantepgtimer.stopmenu.value == "delete" and self.save_current_timeshift:
				# it is only a flag to reset, no recording to delete ...
				self.save_current_timeshift = False 
                                config.plugins.pts.isRecording.value = False
			else:
				self.recordQuestionCallback(("add recording", config.plugins.instantepgtimer.startmenu.value))

# == MultiEPG Vali Mod ============
def MultiEPG_MV_instantRecord(self):
	cprint(">>>> MultiEPG_MV.instantRecord")

	cur = self["list"].getCurrent()
	event = cur[0]
	serviceref = cur[1]
	if event is None:
		return
		
	eventid = event.getEventId()
	refstr = serviceref.ref.toString()
	for timer in self.session.nav.RecordTimer.timer_list:
		if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
			cb_func = lambda ret : not ret or self.removeTimer_new(timer)
			if config.plugins.instantepgtimer.stop.value == "ok":
				cb_func(True)
			else:
				self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
			break
	else:
		newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(event))
		self.finishedAdd((True,newEntry))
		self.updateList()

def MultiEPG_MV_removeTimer(self, timer):    
	cprint(">>>> MultiEPG_MV.removeTimer")
	timer.afterEvent = AFTEREVENT.NONE
	self.session.nav.RecordTimer.removeEntry(timer)
	self["key_green"].setText(_("Add timer"))
	self.key_green_choice = self.ADD_TIMER
	self["key_yellow"].setText(" ")
	self.key_yellow_choice = self.EMPTY
	self.updateList()
	
	if config.plugins.instantepgtimer.delete.value != "no":
		self.deleteRecording(timer)  

def MultiEPG_MV_deleteRecording(self, timer):
	cprint("MultiEPG_MV.removeTimer")
	try:
		filename = timer.Filename
	except:
		filename = ""
	if filename:
		# Thanks Dr.Best !
		service=eServiceReference(eServiceReference.idDVB,0,filename)
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		info = serviceHandler.info(service)
		name = info and info.getName(service) or _("this recording")
		result = False
		if offline is not None:
			# simulate first
			if not offline.deleteFromDisk(1):
				result = True
		if result:
			if config.plugins.instantepgtimer.delete.value == "yes" or self.force_menu:
				self.session.openWithCallback(boundFunction(self.deleteRecordingConfirmed,service), MessageBox, _("Recording")+" "+_("delete file")+": %s ?" % (name))
			else:
				self.deleteRecordingConfirmed(service,True)
		else:
			self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
	else:
		cprint("no recorded file (yet)")

def MultiEPG_MV_deleteRecordingConfirmed(self, service, confirmed):
	if confirmed:
		serviceHandler = eServiceCenter.getInstance()
		offline = serviceHandler.offlineOperations(service)
		if offline is not None:
			# really delete!
			offline.deleteFromDisk(0)

# == End MultiEPG Vali Mod ====================================


def autostart(reason,**kwargs):     
		if kwargs.has_key("session") and reason == 0:
			session = kwargs["session"]
			cprint("autostart ...")
			infomenu=[]
			i=0
			infomenu.append(( str(i), _("Please choose an extension...")))  
			i+=1
			infomenu.append((str(i),_("show EPG...")))  
			i+=1
			for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EVENTINFO):
				i+=1
				infomenu.append((str(i),p.name))
			i+=1
			infomenu.append((str(i),_("show single service EPG...")))
			if config.misc.epgcache_outdated_timespan.value:
				i+=1
				infomenu.append((str(i),_("show outdated service EPG...")))
			i+=1
			infomenu.append((str(i),_("Multi EPG")))
			config.plugins.instantepgtimer.infolong = ConfigSelection(default="0", choices = infomenu)
			config.plugins.instantepgtimer.infoshort = ConfigSelection(default="1", choices = infomenu)
			
			
			# rename on startup
			Screens.EpgSelection.EPGSelection.instantRecord=EPGSelection_instantRecord
			Screens.EpgSelection.EPGSelection.__init__=EPGSelection__init__
			Screens.EpgSelection.EPGSelection.removeTimer=EPGSelection_removeTimer
			Screens.EpgSelection.EPGSelection.deleteRecording=EPGSelection_deleteRecording
			Screens.EpgSelection.EPGSelection.deleteRecordingConfirmed=EPGSelection_deleteRecordingConfirmed
			#Screens.EpgSelection.EPGSelection.doInfo=EPGSelection_doInfo
			# rename on startup
			Screens.EventView.EventViewBase.instantRecord=EventViewBase_instantRecord
			Screens.EventView.EventViewBase.__init__=EventViewBase__init__
			Screens.EventView.EventViewBase.removeTimer=EventViewBase_removeTimer
			Screens.EventView.EventViewBase.deleteRecording=EventViewBase_deleteRecording
			Screens.EventView.EventViewBase.deleteRecordingConfirmed=EventViewBase_deleteRecordingConfirmed
			#rename on startup 
			#Screens.InfoBarGenerics.InfoBarInstantRecord.startInstantRecording=InfoBarInstantRecord_startInstantRecording
			Screens.InfoBarGenerics.InfoBarInstantRecord.instantRecord=InfoBarInstantRecord_instantRecord
			#Screens.InfoBar.InfoBar.instantRecord=InfoBarInstantRecord_instantRecord
			Screens.InfoBarGenerics.InfoBarInstantRecord.changeDuration=InfoBarInstantRecord_changeDuration
			Screens.InfoBarGenerics.InfoBarInstantRecord.__init__=InfoBarInstantRecord__init__
			Screens.InfoBarGenerics.InfoBarInstantRecord.recordQuestionCallback=InfoBarInstantRecord_recordQuestionCallback
			Screens.InfoBarGenerics.InfoBarInstantRecord.removeTimer=InfoBarInstantRecord_removeTimer
			#Screens.InfoBar.InfoBar.removeTimer=InfoBarInstantRecord_removeTimer
			#Screens.InfoBarGenerics.InfoBarInstantRecord.isInstantRecordRunning=InfoBarInstantRecord_isInstantRecordRunning
			Screens.InfoBar.InfoBar.isInstantRecordRunning=InfoBarInstantRecord_isInstantRecordRunning
			
			Screens.InfoBarGenerics.InfoBarInstantRecord.deleteRecording=InfoBarInstantRecord_deleteRecording
			Screens.InfoBarGenerics.InfoBarInstantRecord.deleteRecordingConfirmed=InfoBarInstantRecord_deleteRecordingConfirmed
			Screens.InfoBarGenerics.InfoBarInstantRecord.runningRepeatedTimerCallback=InfoBarInstantRecord_runningRepeatedTimerCallback
			Screens.InfoBarGenerics.InfoBarInstantRecord.stopCurrentRecording=InfoBarInstantRecord_stopCurrentRecording
			#rename on startup 
			Screens.InfoBarGenerics.InfoBarEPG.showEventInfoPlugins=InfoBarEPG_showEventInfoPlugins
			Screens.InfoBarGenerics.InfoBarEPG.openEventView=InfoBarEPG_openEventView
			Screens.InfoBarGenerics.InfoBarEPG.openEventViewOri=InfoBarEPG_ori_openEventView
			Screens.InfoBarGenerics.InfoBarEPG.__init__=InfoBarEPG__init__
			# rename on startup - all stolen from InfoBarGenerics.InfoBarInstantRecord
			Screens.ChannelSelection.ChannelSelectionBase.instantRecord=ChannelSelectionBase_instantRecord
			Screens.ChannelSelection.ChannelSelectionBase.inputCallback=ChannelSelectionBase_inputCallback
			Screens.ChannelSelection.ChannelSelectionBase.changeDuration=ChannelSelectionBase_changeDuration
			Screens.ChannelSelection.ChannelSelectionBase.TimeDateInputClosed=ChannelSelectionBase_TimeDateInputClosed
			Screens.ChannelSelection.ChannelSelectionBase.setEndtime=ChannelSelectionBase_setEndtime
			Screens.ChannelSelection.ChannelSelectionBase.recordQuestionCallback=ChannelSelectionBase_recordQuestionCallback
			Screens.ChannelSelection.ChannelSelectionBase.isInstantRecordRunning=ChannelSelectionBase_isInstantRecordRunning
			Screens.ChannelSelection.ChannelSelectionBase.startInstantRecording=ChannelSelectionBase_startInstantRecording
			Screens.ChannelSelection.ChannelSelectionBase.runningRepeatedTimerCallback=ChannelSelectionBase_runningRepeatedTimerCallback
			Screens.ChannelSelection.ChannelSelectionBase.stopCurrentRecording=ChannelSelectionBase_stopCurrentRecording
			Screens.ChannelSelection.ChannelSelectionBase.timerentryOnStateChange=ChannelSelectionBase_timerentryOnStateChange
			Screens.ChannelSelection.ChannelSelectionBase.removeTimer=ChannelSelectionBase_removeTimer
			Screens.ChannelSelection.ChannelSelectionBase.deleteRecording=ChannelSelectionBase_deleteRecording
			Screens.ChannelSelection.ChannelSelectionBase.deleteRecordingConfirmed=ChannelSelectionBase_deleteRecordingConfirmed
			global ChannelSelectionBase_ori__init__
			ChannelSelectionBase_ori__init__ = Screens.ChannelSelection.ChannelSelectionBase.__init__
			Screens.ChannelSelection.ChannelSelectionBase.__init__= ChannelSelectionBase__init__
			
			# integrate Partnerbox-EPGSelection
			# if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/Partnerbox"):
				# from Plugins.Extensions.Partnerbox.PartnerboxEPGSelection import Partnerbox_EPGSelectionInit, EPGSelection
				# Partnerbox_EPGSelectionInit()
				# global EPGSelection_ori__init__
				# EPGSelection_ori__init__ = Screens.EpgSelection.EPGSelection.__init__
				# Screens.EpgSelection.EPGSelection.__init__ = EPGSelection__init__
			
			# rename on startup 
			Screens.ChannelSelection.ChannelSelectionEPG.showEPGList=ChannelSelectionEPG_showEPGList
			# rename on startup 
			Screens.ChannelSelection.SelectionEventInfo.updateEventInfo=SelectionEventInfo_updateEventInfo
			Screens.ChannelSelection.SelectionEventInfo.play=SelectionEventInfo_play
			Screens.ChannelSelection.SelectionEventInfo.stopStreaming=SelectionEventInfo_stopStreaming
			Screens.ChannelSelection.SelectionEventInfo.__init__=SelectionEventInfo__init__
			# rename on startup
			global MovieSelection_ori__init__
			MovieSelection_ori__init__ = Screens.MovieSelection.MovieSelection.__init__
			Screens.MovieSelection.MovieSelection.instantRecord=MovieSelection_instantRecord
			Screens.MovieSelection.MovieSelection.__init__=MovieSelection__init__
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/EPGSearch"):
				EPGSearch.EPGSearch.__init__=EPGSearch__init__
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/GraphMultiEPG"):
				import Plugins.Extensions.GraphMultiEPG.plugin
				import Plugins.Extensions.GraphMultiEPG.GraphMultiEpg
				from Plugins.Extensions.GraphMultiEPG.GraphMultiEpg import TimelineText as TimelineText
				from Plugins.Extensions.GraphMultiEPG.GraphMultiEpg import EPGList as GraphMultiEPG_EPGList
				# rename on startup
				Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.instantRecord=GraphMultiEPG_instantRecord
				Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.removeTimer=GraphMultiEPG_removeTimer
				Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.deleteRecordingConfirmed=GraphMultiEPG_deleteRecordingConfirmed
				Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.deleteRecording=GraphMultiEPG_deleteRecording
				Plugins.Extensions.GraphMultiEPG.GraphMultiEpg.GraphMultiEPG.__init__=GraphMultiEPG__init__
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPGCenter"):
				import Plugins.Extensions.MerlinEPGCenter.plugin
				import Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter
				import Plugins.Extensions.MerlinEPGCenter.EpgActions
				# rename on startup
				Plugins.Extensions.MerlinEPGCenter.EpgActions.MerlinEPGActions.instantRecord=MerlinEPGCenter_instantRecord
				Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter.MerlinEPGCenter.deleteTimer=MerlinEPGCenter_deleteTimer
				Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter.MerlinEPGCenter.deleteRecording=MerlinEPGCenter_deleteRecording
				Plugins.Extensions.MerlinEPGCenter.MerlinEPGCenter.MerlinEPGCenter.deleteRecordingConfirmed=MerlinEPGCenter_deleteRecordingConfirmed
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/ValisEPG"):
				import Plugins.Extensions.ValisEPG.plugin
				# rename on startup
				Plugins.Extensions.ValisEPG.plugin.ValisEPG.updateEventInfo=ValisEPG_updateEventInfo
				Plugins.Extensions.ValisEPG.plugin.ValisEPG.instantRecord=ValisEPG_instantRecord
				Plugins.Extensions.ValisEPG.plugin.ValisEPG.removeTimer=ValisEPG_removeTimer
				Plugins.Extensions.ValisEPG.plugin.ValisEPG.deleteRecording=ValisEPG_deleteRecording
				Plugins.Extensions.ValisEPG.plugin.ValisEPG.deleteRecordingConfirmed=ValisEPG_deleteRecordingConfirmed
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/PermanentTimeshift"):
				from Screens.InfoBar import InfoBar as InstantEPGTimer_InfoBarOrg
				from Plugins.Extensions.PermanentTimeshift.plugin import InfoBar as PTS_InfoBar
				PTS_InfoBar.instantRecord=PTS_instantRecord
				PTS_InfoBar.isInstantRecordRunning=PTS_isInstantRecordRunning
			if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/MultiEPG_MV"):
				import Plugins.Extensions.MultiEPG_MV.MultiEPG
				# rename on startup
				Plugins.Extensions.MultiEPG_MV.MultiEPG.MultiEPG_MV.instantRecord=MultiEPG_MV_instantRecord
				Plugins.Extensions.MultiEPG_MV.MultiEPG.MultiEPG_MV.removeTimer_new=MultiEPG_MV_removeTimer
				Plugins.Extensions.MultiEPG_MV.MultiEPG.MultiEPG_MV.deleteRecording=MultiEPG_MV_deleteRecording
				Plugins.Extensions.MultiEPG_MV.MultiEPG.MultiEPG_MV.deleteRecordingConfirmed=MultiEPG_MV_deleteRecordingConfirmed

def extensionschannel(session,service=None, **kwargs):                                                     
	if config.plugins.instantepgtimer.channels.value:
		cprint("Cannel Info Menu")
		Screens.InfoBarGenerics.InfoBarEPG.showEventInfoPlugins(Screens.InfoBarGenerics.InfoBarEPG.instance, True)  
	else:
		cprint("instantRecord Menu disabled")

def extensionslong(session,**kwargs):                                                     
	if config.plugins.instantepgtimer.extensions.value:
		cprint("long Info Menu")
		Screens.InfoBarGenerics.InfoBarEPG.showEventInfoPlugins(Screens.InfoBarGenerics.InfoBarEPG.instance, True)  
	else:
		cprint("instantRecord Menu disabled")

def extensionsrec(session,**kwargs):                                                     
	if config.plugins.instantepgtimer.extensions.value:
		if os_path.exists("/usr/lib/enigma2/python/Plugins/Extensions/PermanentTimeshift"):
			cprint("instantRecord PTS Menu")
			from Plugins.Extensions.PermanentTimeshift.plugin import InfoBarOrg as PermanentTimeshift_InfoBarOrg
			from Plugins.Extensions.PermanentTimeshift.plugin import InfoBar as PermanentTimeshift_InfoBar
			PermanentTimeshift_InfoBar.instantRecord(PermanentTimeshift_InfoBarOrg.instance, True)  
		else:
			cprint("instantRecord Standard Menu")
			Screens.InfoBarGenerics.InfoBarInstantRecord.instantRecord(Screens.InfoBarGenerics.InfoBarInstantRecord.instance, True)  
	else:
		cprint("instantRecord Menu disabled")
		session.open(MessageBox, _("Instant Record...").rstrip("...")+" "+_("Menu")+" "+_("disabled"),  MessageBox.TYPE_WARNING)

def startInstantEpgTimer(session,**kwargs):
	session.open(InstantEpgTimer)

def housekeepingInstantEpgTimerExtensionsMenu(el):
	if el.value:
		plugins.addPlugin(extInstantEpgTimerDescriptor)
		plugins.addPlugin(extLongInfoDescriptor)
	else:
		try:
			plugins.removePlugin(extInstantEpgTimerDescriptor)
			plugins.removePlugin(extLongInfoDescriptor)
		except ValueError as ve:
			cprint("housekeeping of Extensionsmenu got confused, tried to remove non-existant plugin entry... ignoring.")

def housekeepingInstantEpgTimerChannelsMenu(el):
	if el.value:
		plugins.addPlugin(extChannelDescriptor)
	else:
		try:
			plugins.removePlugin(extChannelDescriptor)
		except ValueError as ve:
			cprint("housekeeping of Channelsmenu got confused, tried to remove non-existant plugin entry... ignoring.")

config.plugins.instantepgtimer.extensions.addNotifier(housekeepingInstantEpgTimerExtensionsMenu, initial_call = False, immediate_feedback = True)
config.plugins.instantepgtimer.channels.addNotifier(housekeepingInstantEpgTimerChannelsMenu, initial_call = False, immediate_feedback = True)
extInstantEpgTimerDescriptor = PluginDescriptor(name=_("Instant Record...").rstrip("...")+" "+_("Menu"), description=_("Instant Record...").rstrip("...")+" "+_("EPG")+" "+_("Timer")+" "+_("Menu"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=extensionsrec, needsRestart = False)
extLongInfoDescriptor = PluginDescriptor(name=_("Info")+" "+_("EPG")+" "+_("Menu"), description=_("Info")+" "+_("EPG")+" "+_("Menu"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=extensionslong, needsRestart = False)
extChannelDescriptor = PluginDescriptor(name=_("Info")+" "+_("EPG")+" "+_("Menu"), description=_("Info")+" "+_("EPG")+" "+_("Menu"), where = PluginDescriptor.WHERE_CHANNEL_CONTEXT_MENU, fnc=extensionschannel)

def Plugins(**kwargs):
	pl = [

		PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
		PluginDescriptor(name=_("Instant Record...").rstrip("..."), description=_("Instant Record...").rstrip("...")+" "+_("EPG")+" "+_("Timer"), where=PluginDescriptor.WHERE_MENU, fnc=mainconf)
	]
	if config.plugins.instantepgtimer.extensions.value:
		pl.append(extInstantEpgTimerDescriptor)
		pl.append(extLongInfoDescriptor)
	if config.plugins.instantepgtimer.channels.value:
		pl.append(extChannelDescriptor)

	return pl


def mainconf(menuid):
	if menuid != "services_recordings":
		return []
	return [(_("Instant Record...").rstrip("..."), startInstantEpgTimer, "instantepgtimer", None)]

sz_w = getDesktop(0).size().width()

class InstantEpgTimer(Screen, ConfigListScreen):

	if sz_w == 1920:    
		skin = """
		<screen position="center,170" size="1200,620" title="Instant EPG Timer Setup" >
			<widget backgroundColor="#9f1313" font="Regular;30" halign="center" name="buttonred" position="25,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="280,60" valign="center" />
				<widget backgroundColor="#1f771f" font="Regular;30" halign="center" name="buttongreen" position="315,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="280,60" valign="center" />
				<widget backgroundColor="#a08500" font="Regular;30" halign="center" name="buttonyellow" position="605,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="280,60" valign="center" />
				<widget backgroundColor="#18188b" font="Regular;30" halign="center" name="buttonblue" position="895,10" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="280,60" valign="center" />
				<eLabel backgroundColor="grey" position="20,80" size="1160,1" />
				<widget name="config" enableWrapAround="1" position="25,90" scrollbarMode="showOnDemand" size="1150,520" />
		</screen>"""
	elif sz_w == 2560:    
		skin = """
		<screen position="center,180" size="1640,1040" title="Instant EPG Timer" >
			<widget backgroundColor="#9f1313" font="Regular;36" halign="center" name="buttonred" position="30,10" foregroundColor="white" shadowColor="black" shadowOffset="-4,-4" size="380,80" valign="center" />
			<widget backgroundColor="#1f771f" font="Regular;36" halign="center" name="buttongreen" position="430,10" foregroundColor="white" shadowColor="black" shadowOffset="-4,-4" size="380,80" valign="center" />
			<widget backgroundColor="#a08500" font="Regular;36" halign="center" name="buttonyellow" position="830,10" foregroundColor="white" shadowColor="black" shadowOffset="-4,-4" size="380,80" valign="center" />
			<widget backgroundColor="#18188b" font="Regular;36" halign="center" name="buttonblue" position="1230,10" foregroundColor="white" shadowColor="black" shadowOffset="-4,-4" size="380,80" valign="center" />
			<eLabel backgroundColor="grey" position="20,120" size="1600,2" />
			<widget name="config" enableWrapAround="1" position="30,140" size="1580,840" scrollbarMode="showOnDemand" />
		</screen>"""
	else:
		skin = """
		<screen position="center,120" size="820,460" title="Instant EPG Timer" >
			<widget backgroundColor="#9f1313" font="Regular;18" halign="center" name="buttonred" position="15,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="190,40" valign="center" />
				<widget backgroundColor="#1f771f" font="Regular;18" halign="center" name="buttongreen" position="215,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="190,40" valign="center" />
				<widget backgroundColor="#a08500" font="Regular;18" halign="center" name="buttonyellow" position="415,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="190,40" valign="center" />
				<widget backgroundColor="#18188b" font="Regular;18" halign="center" name="buttonblue" position="615,5" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" size="190,40" valign="center" />
				<eLabel backgroundColor="grey" position="10,60" size="800,1" />
			<widget name="config" enableWrapAround="1" position="15,70" size="790,360" scrollbarMode="showOnDemand" />
		</screen>"""

	def __init__(self, session, args = 0):
		Screen.__init__(self, session)
		self.skin = InstantEpgTimer.skin  
		self.onShown.append(self.setWindowTitle)
		# explicit check on every entry
		self.list = []
		ConfigListScreen.__init__(self, self.list, session = self.session)
		self.createSetup()       
		self["buttonred"] = Label(_("Exit"))
		self["buttongreen"] = Label(_("Save"))
		self["buttonyellow"] = Label(_("-"))
		self["buttonblue"] = Label(_("About"))
		self["actions"] = ActionMap(["SetupActions", "ColorActions"],{"ok": self.save,  "exit": self.cancel, "cancel": self.cancel, "red": self.cancel, "green": self.save, "yellow": self.about, "blue": self.about, })

	def setWindowTitle(self):
		self.setTitle(_("Instant Record...").rstrip("...")+" "+_("EPG")+" "+_("Timer")+" "+_("Setup"))

	def save(self):
		for x in self["config"].list:
			x[1].save()
		self.close(True)

	def cancel(self):
		for x in self["config"].list:
			x[1].cancel()
		self.close(False)

	def about(self):
		self.session.open(MessageBox, _("Instant Record...").rstrip("...")+" "+_("EPG")+" "+_("Timer")+" "+_("Plugin")+" "+_("Version")+" "+instantepgtimer_version+"\n\n"+_("(c) gutemine & Dreamy"),  MessageBox.TYPE_INFO)

	def createSetup(self):                                                  
		self.list = []
		self.list.append(getConfigListEntry(_("Configuring")+" "+_("stop recording"), config.plugins.instantepgtimer.stop))
		self.list.append(getConfigListEntry(_("Recording")+" "+_("delete file"), config.plugins.instantepgtimer.delete))
		self.list.append(getConfigListEntry(_("Menu")+" "+_("start"), config.plugins.instantepgtimer.startmenu))
		self.list.append(getConfigListEntry(_("Menu")+" "+_("stop"), config.plugins.instantepgtimer.stopmenu))
		self.list.append(getConfigListEntry(_("Default")+" "+_("Timer")+" "+_("length")+" ["+_("mins")+"]", config.plugins.instantepgtimer.length))
		if SystemInfo.get("NumVideoDecoders", 1) > 1:
			self.list.append(getConfigListEntry(_("Channel Selection")+" "+_("Poll automatically").lower()+" "+_("EPG"), config.plugins.instantepgtimer.loadepg))
		self.list.append(getConfigListEntry(_("Channel Selection")+" "+_("Show recordings")+" "+_("textcolor"), config.usage.configselection_showrecordings))
		self.list.append(getConfigListEntry(_("Menu")+" "+_("Extensions")+" "+_("show all").lower(), config.plugins.instantepgtimer.extensions))
		self.list.append(getConfigListEntry(_("Channellist menu")+" "+_("show all").lower(), config.plugins.instantepgtimer.channels))
		self.list.append(getConfigListEntry(_("Default")+" "+_("Info"), config.plugins.instantepgtimer.infoshort))
		self.list.append(getConfigListEntry(_("Long Keypress")+" "+_("Info"), config.plugins.instantepgtimer.infolong))
		self.list.append(getConfigListEntry(_("Channel Selection")+" "+_("Info"), config.plugins.instantepgtimer.infodirect))
		self["config"].list = self.list                                 
		self["config"].l.setList(self.list)