def bareGetSeasonEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False):
	result = None
	if config.plugins.seriesplugin.enabled.value:
		
		startLog()
		
		logInfo("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisodeBlocking(
			name, begin, end, service_ref, future, today, elapsed
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and len(data) == 4:
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			logInfo("Bare: Success", name, description, path)
			return (name, description, path, getLog())
		elif data:
			global loop_data
			loop_data.append( str(data) )
		
		logInfo("Bare: Failed", str(data))
		return str(data)
	
	return result
def bareGetSeasonEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False):
	result = _("SeriesPlugin is deactivated")
	if config.plugins.seriesplugin.enabled.value:
		
		startLog()
		
		logInfo("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisodeBlocking(
			name, begin, end, service_ref, future, today, elapsed
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and isinstance(data, dict):
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			logInfo("Bare: Success", name, description, path)
			return (name, description, path, getLog())
		elif data:
			global loop_data
			loop_data.append( str(data) )
		
		logInfo("Bare: Failed", str(data))
		return str(data)
	
	return result
	def __init__(self, session, service=None, event=None):
		Screen.__init__(self, session)
		
		global instance
		instance = self
		
		self.session = session
		self.skinName = [ "SeriesPluginInfoScreen" ]
		
		self["logo"] = Pixmap()
		self["cover"] = Pixmap()
		self["state"] = Pixmap()
		
		self["event_title"] = Label()
		self["event_episode"] = Label()
		self["event_description"] = ScrollLabel()
		self["datetime"] = Label()
		self["channel"] = Label()
		self["duration"] = Label()
		
		self["key_red"] = Button("")				# Rename or Record
		self["key_green"] = Button("")			# Trakt Seen / Not Seen
		self["key_yellow"] = Button("")			# Show all Episodes of current season
		self["key_blue"] = Button("")				# Show all Seasons
		
		self.redButtonFunction = None
		
		#TODO HelpableActionMap
		self["actions"] = ActionMap(["OkCancelActions", "EventViewActions", "DirectionActions", "ColorActions"],
		{
			"cancel":    self.close,
			"ok":        self.close,
			"up":        self["event_description"].pageUp,
			"down":      self["event_description"].pageDown,
			"red":       self.redButton,
			"prevEvent": self.prevEpisode,
			"nextEvent": self.nextEpisode,
			
			#TODO
			#"pageUp":    self.pageUp,
			#"pageDown":  self.pageDown,
			#"openSimilarList": self.openSimilarList
		})
		
		splog("SPI: SeriesPluginInfo", service, event)
		self.service = service
		self.event = event
		
		self.name = ""
		self.short = ""
		self.data = None
		
		self.path = None
		self.eservice = None
		
		self.epg = eEPGCache.getInstance()
		self.serviceHandler = eServiceCenter.getInstance()
		self.seriesPlugin = getInstance()
		
		self.onLayoutFinish.append( self.layoutFinished )
	def timerCallback(self, timer, data=None):
		splog("SPT: timerCallback", data)
		splog(data)
		
		if data and len(data) == 4 and timer:
			
			# Episode data available, refactor name and description
			#from SeriesPluginRenamer import newLegacyEncode
			timer.name = str(refactorTitle(timer.name, data))
			#timer.name = newLegacyEncode(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			timer.log(610, "[SeriesPlugin] Success: Changed name: %s." % (timer.name))
		
		elif data:
			timer.log(611, "[SeriesPlugin] Failed: %s." % ( str( data ) ))
			SeriesPluginTimer.data.append(
				str(timer.name) + " " + str( data )
			)
		
		else:
			timer.log(612, "[SeriesPlugin] Failed." )
			SeriesPluginTimer.data.append(
				str(timer.name) + " " + _("No data available")
			)
		
		timer.sp_in_queue = False
		
		if config.plugins.seriesplugin.timer_popups.value or config.plugins.seriesplugin.timer_popups_success.value:
			
			SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
			
			if SeriesPluginTimer.data or config.plugins.seriesplugin.timer_popups_success.value:
				
				# Maybe there is a better way to avoid multiple Popups
				from SeriesPlugin import getInstance
				
				instance = getInstance()
				
				if instance.thread.empty() and instance.thread.finished():
				
					if SeriesPluginTimer.data:
						AddPopup(
							"SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data),
							MessageBox.TYPE_ERROR,
							int(config.plugins.seriesplugin.timer_popups_timeout.value),
							'SP_PopUp_ID_TimerFinished'
						)
					else:
						AddPopup(
							"SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter),
							MessageBox.TYPE_INFO,
							int(config.plugins.seriesplugin.timer_popups_timeout.value),
							'SP_PopUp_ID_TimerFinished'
						)
					SeriesPluginTimer.data = []
					SeriesPluginTimer.counter = 0
		
		return timer
Exemple #5
0
	def timerCallback(self, timer, data=None):
		log.debug("timerCallback", data)
		
		if data and isinstance(data, dict) and timer:
			
			# Episode data available, refactor name and description
			timer.name = str(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			timer.dirname = str(refactorDirectory(timer.dirname or config.usage.default_path.value, data))
			timer.calculateFilename()
			
			msg = _("Success: %s" % (timer.name))
			log.debug(msg)
			timer.log(610, "[SeriesPlugin]" + " " + msg)
			
			if config.plugins.seriesplugin.timer_add_tag.value:
				timer.tags.append(TAG)
		
		elif data:
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			timer.log(611, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		else:
			msg = _("No data available")
			log.debug(msg)
			timer.log(612, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		timer.sp_in_queue = False
		
		SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
		
		# Maybe there is a better way to avoid multiple Popups
		from SeriesPlugin import getInstance
		
		instance = getInstance()
		
		if instance.thread.empty() and instance.thread.finished():
		
			if SeriesPluginTimer.data:
				msg = "SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data)
				log.warning(msg)
				
			else:
				if SeriesPluginTimer.counter > 0:
					msg = "SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter)
					log.success(msg)
				
			SeriesPluginTimer.data = []
			SeriesPluginTimer.counter = 0
		
		return timer
	def timerCallback(self, timer, data=None):
		log.debug("timerCallback", data)
		
		if data and isinstance(data, dict) and timer:
			
			# Episode data available, refactor name and description
			timer.name = str(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			timer.dirname = str(refactorDirectory(timer.dirname or config.usage.default_path.value, data))
			timer.calculateFilename()
			
			msg = _("Success: %s" % (timer.name))
			log.debug(msg)
			timer.log(610, "[SeriesPlugin]" + " " + msg)
			
			if config.plugins.seriesplugin.timer_add_tag.value:
				timer.tags.append(TAG)
		
		elif data:
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			timer.log(611, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		else:
			msg = _("No data available")
			log.debug(msg)
			timer.log(612, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		timer.sp_in_queue = False
		
		SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
		
		# Maybe there is a better way to avoid multiple Popups
		from SeriesPlugin import getInstance
		
		instance = getInstance()
		
		if instance.thread.empty() and instance.thread.finished():
		
			if SeriesPluginTimer.data:
				msg = "SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data)
				log.warning(msg)
				
			else:
				if SeriesPluginTimer.counter > 0:
					msg = "SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter)
					log.success(msg)
				
			SeriesPluginTimer.data = []
			SeriesPluginTimer.counter = 0
		
		return timer
def bareGetEpisode(service_ref,
                   name,
                   begin,
                   end,
                   description,
                   path,
                   future=True,
                   today=False,
                   elapsed=False):
    result = _("SeriesPlugin is deactivated")
    if config.plugins.seriesplugin.enabled.value:

        log.start()

        log.info("Bare:", service_ref, name, begin, end, description, path,
                 future, today, elapsed)

        from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
        seriesPlugin = getInstance()
        data = seriesPlugin.getEpisode(None,
                                       name,
                                       begin,
                                       end,
                                       service_ref,
                                       future,
                                       today,
                                       elapsed,
                                       block=True)

        global loop_counter
        loop_counter += 1

        if data and isinstance(data, dict):
            name = str(refactorTitle(name, data))
            description = str(refactorDescription(description, data))
            path = refactorDirectory(path, data)
            log.info("Bare: Success", name, description, path)
            return (name, description, path, log.get())

        elif data and isinstance(data, basestring):
            global loop_data
            msg = _("Failed: %s." % (str(data)))
            log.debug(msg)
            loop_data.append(name + ": " + msg)

        else:
            global loop_data
            msg = _("No data available")
            log.debug(msg)
            loop_data.append(name + ": " + msg)

        log.info("Bare: Failed", str(data))
        return str(data)

    return result
	def renamerCallback(self, servicepath, name, short, data=None):
		log.debug("renamerCallback", name, data)
		
		result = None
		
		if data and isinstance(data, dict):
			result = rename(servicepath, name, short, data)
		
		elif data and isinstance(data, basestring):
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			self.data.append( name + ": " + msg )
		
		else:
			msg = _("No data available")
			log.debug(msg)
			self.data.append( name + ": " + msg )
		
		if config.plugins.seriesplugin.rename_popups.value or config.plugins.seriesplugin.rename_popups_success.value:
			
			self.counter = self.counter +1
			
			if self.data or config.plugins.seriesplugin.rename_popups_success.value:
			
				# Maybe there is a better way to avoid multiple Popups
				from SeriesPlugin import getInstance
				
				instance = getInstance()
				
				if instance.thread.empty() and instance.thread.finished():
					if self.data:
						AddPopup(
							"SeriesPlugin:\n" + _("Record rename has been finished with %d errors:\n") % (len(self.data)) +"\n" +"\n".join(self.data),
							MessageBox.TYPE_ERROR,
							int(config.plugins.seriesplugin.rename_popups_timeout.value),
							'SP_PopUp_ID_RenameFinished'
						)
					else:
						AddPopup(
							"SeriesPlugin:\n" + _("%d records renamed successfully") % (self.counter),
							MessageBox.TYPE_INFO,
							int(config.plugins.seriesplugin.rename_popups_timeout.value),
							'SP_PopUp_ID_RenameFinished'
						)
					self.data = []
					self.counter = 0
def bareGetEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False, returnData=False):
	result = _("SeriesPlugin is deactivated")
	if config.plugins.seriesplugin.enabled.value:
		
		log.start()
		
		log.info("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisode(
			None, 
			name, begin, end, service_ref, future, today, elapsed, block=True
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and isinstance(data, dict):
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			log.info("Bare: Success", name, description, path)
			if returnData:
				return (name, description, path, log.get(), data)
			else:
				return (name, description, path, log.get())
		
		elif data and isinstance(data, basestring):
			global loop_data
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			loop_data.append( name + ": " + msg )
		
		else:
			global loop_data
			msg = _("No data available")
			log.debug(msg)
			loop_data.append( name + ": " + msg )
		
		log.info("Bare: Failed", str(data))
		return str(data)
	
	return result
Exemple #10
0
    def renamerCallback(self, servicepath, name, short, data=None):
        logDebug("SPR: renamerCallback", name, data)

        result = None

        if data and len(data) == 4:
            result = rename(servicepath, name, short, data)

        if result and isinstance(result, basestring):
            self.data.append(result)

        if config.plugins.seriesplugin.rename_popups.value or config.plugins.seriesplugin.rename_popups_success.value:

            self.counter = self.counter + 1

            if self.data or config.plugins.seriesplugin.rename_popups_success.value:

                # Maybe there is a better way to avoid multiple Popups
                from SeriesPlugin import getInstance

                instance = getInstance()

                if instance.thread.empty() and instance.thread.finished():
                    if self.data:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("Record rename has been finished with %d errors:\n"
                              ) % (len(self.data)) + "\n" +
                            "\n".join(self.data), MessageBox.TYPE_ERROR,
                            int(config.plugins.seriesplugin.
                                rename_popups_timeout.value),
                            'SP_PopUp_ID_RenameFinished')
                    else:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("%d records renamed successfully") %
                            (self.counter), MessageBox.TYPE_INFO,
                            int(config.plugins.seriesplugin.
                                rename_popups_timeout.value),
                            'SP_PopUp_ID_RenameFinished')
                    self.data = []
                    self.counter = 0
Exemple #11
0
    def renamerCallback(self, servicepath, name, short, data=None):
        log.debug("renamerCallback", name, data)

        result = None

        if data and isinstance(data, dict):
            result = rename(servicepath, name, short, data)

        elif data and isinstance(data, basestring):
            msg = _("Failed: %s." % (str(data)))
            log.debug(msg)
            self.data.append(name + ": " + msg)

        else:
            msg = _("No data available")
            log.debug(msg)
            self.data.append(name + ": " + msg)

        self.counter = self.counter + 1

        # Maybe there is a better way to avoid multiple Popups
        from SeriesPlugin import getInstance

        instance = getInstance()

        if instance.thread.empty() and instance.thread.finished():
            if self.data:
                msg = "SeriesPlugin:\n" + _(
                    "Record rename has been finished with %d errors:\n") % (
                        len(self.data)) + "\n" + "\n".join(self.data)
                log.warning(msg)

            else:
                if self.counter > 0:
                    msg = "SeriesPlugin:\n" + _(
                        "%d records renamed successfully") % (self.counter)
                    log.success(msg)

            self.data = []
            self.counter = 0
	def renamerCallback(self, servicepath, name, short, data=None):
		log.debug("renamerCallback", name, data)
		
		result = None
		
		if data and isinstance(data, dict):
			result = rename(servicepath, name, short, data)
		
		elif data and isinstance(data, basestring):
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			self.data.append( name + ": " + msg )
		
		else:
			msg = _("No data available")
			log.debug(msg)
			self.data.append( name + ": " + msg )
		
		self.counter = self.counter +1
		
		# Maybe there is a better way to avoid multiple Popups
		from SeriesPlugin import getInstance
		
		instance = getInstance()
		
		if instance.thread.empty() and instance.thread.finished():
			if self.data:
				msg = "SeriesPlugin:\n" + _("Record rename has been finished with %d errors:\n") % (len(self.data)) +"\n" +"\n".join(self.data)
				log.warning(msg)
				
			else:
				if self.counter > 0:
					msg = "SeriesPlugin:\n" + _("%d records renamed successfully") % (self.counter)
					log.success(msg)
				
			self.data = []
			self.counter = 0
Exemple #13
0
	def __init__(self, session):
		Screen.__init__(self, session)
		self.skinName = [ "SeriesPluginConfiguration" ]
		
		from plugin import NAME, VERSION
		self.setup_title = NAME + " " + _("Configuration") + " " + VERSION
		
		log.debug("SeriesPluginConfiguration")
		
		self.onChangedEntry = [ ]
		
		# Buttons
		self["key_red"] = Button(_("Cancel"))
		self["key_green"] = Button(_("OK"))
		self["key_blue"] = Button(_("Show Log"))
		self["key_yellow"] = Button(_("Channel Edit"))
		
		# Define Actions
		self["actions"] = ActionMap(["SetupActions", "ChannelSelectBaseActions", "ColorActions"],
		{
			"cancel":		self.keyCancel,
			"save":			self.keySave,
			"nextBouquet":	self.pageUp,
			"prevBouquet":	self.pageDown,
			"blue":			self.showLog,
			"yellow":		self.openChannelEditor,
			"ok": 			self.keyOK,
			"left": 		self.keyLeft,
			"right": 		self.keyRight,
		}, -2) # higher priority
		
		stopIndependent()
		#resetInstance()
		self.seriesPlugin = getInstance()
		
		# Create temporary identifier config elements
		identifiers = self.seriesPlugin.modules
		identifiers_elapsed = [k for k,v in identifiers.items() if v.knowsElapsed()]
		identifiers_today   = [k for k,v in identifiers.items() if v.knowsToday()]
		identifiers_future  = [k for k,v in identifiers.items() if v.knowsFuture()]
		if config.plugins.seriesplugin.identifier_elapsed.value in identifiers_elapsed:
			self.cfg_identifier_elapsed = NoSave( ConfigSelection(choices = identifiers_elapsed, default = config.plugins.seriesplugin.identifier_elapsed.value) )
		else:
			self.cfg_identifier_elapsed = NoSave( ConfigSelection(choices = identifiers_elapsed, default = identifiers_elapsed[0]) )
			self.changesMade = True
		if config.plugins.seriesplugin.identifier_today.value in identifiers_today:
			self.cfg_identifier_today   = NoSave( ConfigSelection(choices = identifiers_today,   default = config.plugins.seriesplugin.identifier_today.value) )
		else:
			self.cfg_identifier_today   = NoSave( ConfigSelection(choices = identifiers_today,   default = identifiers_today[0]) )
			self.changesMade = True
		if config.plugins.seriesplugin.identifier_future.value in identifiers_future:
			self.cfg_identifier_future  = NoSave( ConfigSelection(choices = identifiers_future,  default = config.plugins.seriesplugin.identifier_future.value) )
		else:
			self.cfg_identifier_future  = NoSave( ConfigSelection(choices = identifiers_future,  default = identifiers_future[0]) )
			self.changesMade = True
		
		# Load patterns
		patterns_file = readFilePatterns()
		self.cfg_pattern_title       = NoSave( ConfigSelection(choices = patterns_file, default = config.plugins.seriesplugin.pattern_title.value ) )
		self.cfg_pattern_description = NoSave( ConfigSelection(choices = patterns_file, default = config.plugins.seriesplugin.pattern_description.value ) )
		#self.cfg_pattern_record     = NoSave( ConfigSelection(choices = patterns_file, default = config.plugins.seriesplugin.pattern_record.value ) )
		patterns_directory = readDirectoryPatterns()
		self.cfg_pattern_directory   = NoSave( ConfigSelection(choices = patterns_directory, default = config.plugins.seriesplugin.pattern_directory.value ) )
		
		bouquetList = [("", "")]
		tvbouquets = getTVBouquets()
		for bouquet in tvbouquets:
			bouquetList.append((bouquet[1], bouquet[1]))
		self.cfg_bouquet_main = NoSave( ConfigSelection(choices = bouquetList,  default = config.plugins.seriesplugin.bouquet_main.value or str(list(zip(*bouquetList)[1]))   )  )
		
		checkList( self.cfg_pattern_title )
		checkList( self.cfg_pattern_description )
		checkList( self.cfg_pattern_directory )
		checkList( self.cfg_bouquet_main )
		
		self.changesMade = False
		
		# Initialize Configuration
		self.list = []
		self.buildConfig()
		ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
		
		self.changed()
		self.onLayoutFinish.append(self.layoutFinished)
Exemple #14
0
    def confirm(self, confirmed):
        if confirmed and self.services:
            serviceHandler = eServiceCenter.getInstance()

            try:
                for service in self.services:

                    seriesPlugin = getInstance()

                    if isinstance(service, eServiceReference):
                        service = service
                    elif isinstance(service, ServiceReference):
                        service = service.ref
                    else:
                        log.debug("Wrong instance")
                        continue

                    servicepath = service.getPath()

                    if not os.path.exists(servicepath):
                        log.debug("File not exists: " + servicepath)
                        continue

                    info = serviceHandler.info(service)
                    if not info:
                        log.debug("No info available: " + servicepath)
                        continue

                    short = ""
                    begin = None
                    end = None
                    duration = 0

                    event = info.getEvent(service)
                    if event:
                        name = event.getEventName() or ""
                        short = event.getShortDescription()
                        begin = event.getBeginTime()
                        duration = event.getDuration() or 0
                        end = begin + duration or 0
                        # We got the exact start times, no need for margin handling
                        log.debug("event")
                    else:
                        name = service.getName() or info.getName(service) or ""
                        if name[-2:] == 'ts':
                            name = name[:-2]
                        log.debug("not event")

                    if not begin:
                        begin = info.getInfo(
                            service, iServiceInformation.sTimeCreate) or -1
                        if begin != -1:
                            end = begin + (info.getLength(service) or 0)
                        else:
                            end = os.path.getmtime(servicepath)
                            begin = end - (info.getLength(service) or 0)

                        #MAYBE we could also try to parse the filename
                        log.debug(
                            "We don't know the exact margins, we will assume the E2 default margins"
                        )
                        begin -= (int(config.recording.margin_before.value) *
                                  60)
                        end += (int(config.recording.margin_after.value) * 60)

                    rec_ref_str = info.getInfoString(
                        service, iServiceInformation.sServiceref)
                    #channel = ServiceReference(rec_ref_str).getServiceName()

                    log.debug("getEpisode:", name, begin, end, rec_ref_str)
                    seriesPlugin.getEpisode(boundFunction(
                        self.renamerCallback, servicepath, name, short),
                                            name,
                                            begin,
                                            end,
                                            rec_ref_str,
                                            elapsed=True,
                                            block=True,
                                            rename=True)

            except Exception as e:
                log.exception("Exception:", str(e))
	def confirm(self, confirmed):
		if confirmed and self.services:
			serviceHandler = eServiceCenter.getInstance()
			
			try:
				for service in self.services:
				
					seriesPlugin = getInstance()
					
					if isinstance(service, eServiceReference):
						service = service
					elif isinstance(service, ServiceReference):
						service = service.ref
					else:
						logDebug("SPR: Wrong instance")
						continue
					
					servicepath = service.getPath()
					
					if not os.path.exists( servicepath ):
						logDebug("SPR: File not exists: " + servicepath)
						continue
					
					info = serviceHandler.info(service)
					if not info:
						logDebug("SPR: No info available: " + servicepath)
						continue
					
					name = service.getName() or info.getName(service) or ""
					if name[-2:] == 'ts':
						name = name[:-2]
					#logDebug("SPR: name", name)
					
					short = ""
					begin = None
					end = None
					duration = 0
					
					event = info.getEvent(service)
					if event:
						short = event.getShortDescription()
						begin = event.getBeginTime()
						duration = event.getDuration() or 0
						end = begin + duration or 0
						# We got the exact start times, no need for margin handling
					
					if not begin:
						begin = info.getInfo(service, iServiceInformation.sTimeCreate) or -1
						if begin != -1:
							end = begin + (info.getLength(service) or 0)
						else:
							end = os.path.getmtime(servicepath)
							begin = end - (info.getLength(service) or 0)
						#MAYBE we could also try to parse the filename
						# We don't know the exact margins, we will assume the E2 default margins
						begin -= (int(config.recording.margin_before.value) * 60)
						end += (int(config.recording.margin_after.value) * 60)
					
					rec_ref_str = info.getInfoString(service, iServiceInformation.sServiceref)
					#channel = ServiceReference(rec_ref_str).getServiceName()
					
					logDebug("SPR: getEpisode:", name, begin, end, rec_ref_str)
					seriesPlugin.getEpisode(
							boundFunction(self.renamerCallback, servicepath, name, short),
							name, begin, end, rec_ref_str, elapsed=True, rename=True
						)
					
					#result = seriesPlugin.getEpisodeBlocking( name, begin, end, rec_ref_str, elapsed=True )
					#self.renamerCallback( servicepath, name, short, result )
					
			except Exception as e:
				logDebug("SPR: Exception:", str(e))
    def getSeasonAndEpisode(self, timer, name, begin, end, block=True):

        logInfo("SeriesPluginTimer: timername, service, name, begin, end:",
                timer.name, str(timer.service_ref.ref), name, begin, end)

        if hasattr(timer, 'sp_in_queue'):
            if timer.sp_in_queue:
                logDebug(
                    "SPT: SeriesPluginTimer: Skip timer is already in queue:",
                    timer.name)
                timer.log(
                    601, "[SeriesPlugin] Skip timer is already in queue %s" %
                    (timer.name))
                return

        # We have to compare the length,
        # because of the E2 special chars handling for creating the filenames
        #if timer.name == name:
        # Mad Men != Mad_Men

        if TAG in timer.tags:
            logDebug(
                "SPT: SeriesPluginTimer: Skip timer is already handled %s",
                timer.name)
            timer.log(
                607, "[SeriesPlugin] Skip timer is already handled %s" %
                (timer.name))
            return

        if config.plugins.seriesplugin.timer_eit_check.value:

            event = None
            epgcache = eEPGCache.getInstance()

            if timer.eit:
                #logDebug("SPT: Timer Eit is set", timer.service_ref.ref, timer.eit)
                event = epgcache.lookupEventId(timer.service_ref.ref,
                                               timer.eit)
                logDebug("SPT: LookupEventId", timer.eit, event)
            if not (event):
                #logDebug("Lookup EventTime", timer.service_ref.ref, end, begin)
                event = epgcache.lookupEventTime(timer.service_ref.ref,
                                                 begin + ((end - begin) / 2))
                logDebug("SPT: lookupEventTime", event)
            #if not(event):
            #	logDebug("Lookup Event", timer.service_ref.ref, end, begin)
            #	events = epgcache.lookupEvent( [ "T" , ( timer.service_ref.ref, 0, begin + ((end - begin) /2) ) ] );
            #	logDebug("LookupEvent event(s) found", len(events), events )
            #	event = events and events[0]

            if event:
                #logDebug("EPG event found")
                if not (len(timer.name) == len(name) == len(
                        event.getEventName())):
                    logDebug("SPT: Skip timer because it is already modified",
                             timer.name, name, event and event.getEventName(),
                             len(timer.name), len(name),
                             len(event.getEventName()))
                    timer.log(
                        602,
                        "[SeriesPlugin] Skip timer because it is already modified"
                    )
                    return
            else:
                if (len(timer.name) == len(name)):
                    logDebug("SPT: Skip timer because no event was found",
                             timer.name, name, len(timer.name), len(name))
                    timer.log(
                        603,
                        "[SeriesPlugin] Skip timer because no event was found")
                    return

        if timer.begin < time() + 60:
            logDebug(
                "SPT: Skipping timer because it starts in less than 60 seconds",
                timer.name)
            timer.log(
                604,
                "[SeriesPlugin] Skip timer because it starts in less than 60 seconds"
            )
            return

        if timer.isRunning():
            logDebug("SPT: Skipping timer because it is already running",
                     timer.name)
            timer.log(
                605, "[SeriesPlugin] Skip timer because it is already running")
            return

        if timer.justplay:
            logDebug("SPT: Skipping justplay timer", timer.name)
            timer.log(606, "[SeriesPlugin] Skip justplay timer")
            return

        timer.log(600,
                  "[SeriesPlugin] Try to find infos for %s" % (timer.name))

        seriesPlugin = getInstance()

        if timer.service_ref:
            #channel = timer.service_ref.getServiceName()
            #logDebug(channel)

            logDebug("SPT: getEpisode:", name, begin, end, block)

            timer.sp_in_queue = True

            if block:
                result = seriesPlugin.getEpisodeBlocking(name,
                                                         begin,
                                                         end,
                                                         timer.service_ref,
                                                         future=True)
                return self.timerCallback(timer, result)
            else:
                seriesPlugin.getEpisode(
                    boundFunction(self.timerCallback, timer),
                    #name, begin, end, channel, future=True
                    name,
                    begin,
                    end,
                    timer.service_ref,
                    future=True)
                return None
        else:
            logDebug("SPT: SeriesPluginTimer: No channel specified")
            self.timerCallback(timer, "No channel specified")
            return None
Exemple #17
0
	def getEpisode(self, timer, block=False):
		
		log.info("timername, service, begin, end:", timer.name, str(timer.service_ref.ref), timer.begin, timer.end)
		
		if hasattr(timer, 'sp_in_queue'):
			if timer.sp_in_queue:
				msg = _("Skipping timer because it is already in queue")
				log.warning(msg, timer.name)
				timer.log(601, "[SeriesPlugin]" + " " + msg )
				return
		
		# We have to compare the length,
		# because of the E2 special chars handling for creating the filenames
		#if timer.name == name:
		# Mad Men != Mad_Men
		
		if TAG in timer.tags:
			msg = _("Skipping timer because it is already handled") + "\n\n" + _("Can be configured within the setup")
			log.info(msg, timer.name)
			timer.log(607, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.begin < time() + 60:
			msg = _("Skipping timer because it starts in less than 60 seconds")
			log.debug(msg, timer.name)
			timer.log(604, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.isRunning():
			msg = _("Skipping timer because it is already running")
			log.debug(msg, timer.name)
			timer.log(605, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.justplay:
			msg = _("Skipping timer because it is a just play timer")
			log.debug(msg, timer.name)
			timer.log(606, "[SeriesPlugin]" + " " + msg )
			return
		
		
		event = None
		epgcache = eEPGCache.getInstance()
		
		if timer.eit:
			event = epgcache.lookupEventId(timer.service_ref.ref, timer.eit)
			log.debug("lookupEventId", timer.eit, event)
		if not(event):
			event = epgcache.lookupEventTime( timer.service_ref.ref, timer.begin + ((timer.end - timer.begin) /2) );
			log.debug("lookupEventTime", event )
		
		if event:
			if not ( len(timer.name) == len(event.getEventName()) ):
				msg = _("Skipping timer because it is already modified %s" % (timer.name) )
				log.info(msg)
				timer.log(602, "[SeriesPlugin]" + " " + msg )
				return
			begin = event.getBeginTime() or 0
			duration = event.getDuration() or 0
			end = begin + duration
			
		else:
			if config.plugins.seriesplugin.timer_eit_check.value:
				msg = _("Skipping timer because no event was found")
				log.info(msg, timer.name)
				timer.log(603, "[SeriesPlugin]" + " " + msg )
				return
			else:
				# We don't know the exact margins, we will assume the E2 default margins
				log.debug("We don't know the exact margins, we will assume the E2 default margins")
				begin = timer.begin + (config.recording.margin_before.value * 60)
				end = timer.end - (config.recording.margin_after.value * 60)
		
		
		timer.log(600, "[SeriesPlugin]" + " " + _("Try to find infos for %s" % (timer.name) ) )
		
		seriesPlugin = getInstance()
		
		if timer.service_ref:
			log.debug("getEpisode:", timer.name, timer.begin, timer.end, block)
			
			timer.sp_in_queue = True
			
			return seriesPlugin.getEpisode(
					boundFunction(self.timerCallback, timer),
					timer.name, begin, end, timer.service_ref, future=True, block=block
				)
		else:
			msg = _("Skipping lookup because no channel is specified")
			log.warning(msg)
			self.timerCallback(timer, msg)
			return None
	def getEpisode(self, timer, block=False):
		
		log.info("timername, service, begin, end:", timer.name, str(timer.service_ref.ref), timer.begin, timer.end)
		
		if hasattr(timer, 'sp_in_queue'):
			if timer.sp_in_queue:
				msg = _("Skipping timer because it is already in queue")
				log.warning(msg, timer.name)
				timer.log(601, "[SeriesPlugin]" + " " + msg )
				return
		
		# We have to compare the length,
		# because of the E2 special chars handling for creating the filenames
		#if timer.name == name:
		# Mad Men != Mad_Men
		
		if TAG in timer.tags:
			msg = _("Skipping timer because it is already handled") + "\n\n" + _("Can be configured within the setup")
			log.info(msg, timer.name)
			timer.log(607, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.begin < time() + 60:
			msg = _("Skipping timer because it starts in less than 60 seconds")
			log.debug(msg, timer.name)
			timer.log(604, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.isRunning():
			msg = _("Skipping timer because it is already running")
			log.debug(msg, timer.name)
			timer.log(605, "[SeriesPlugin]" + " " + msg )
			return
		
		if timer.justplay:
			msg = _("Skipping timer because it is a just play timer")
			log.debug(msg, timer.name)
			timer.log(606, "[SeriesPlugin]" + " " + msg )
			return
		
		
		event = None
		epgcache = eEPGCache.getInstance()
		
		if timer.eit:
			event = epgcache.lookupEventId(timer.service_ref.ref, timer.eit)
			log.debug("lookupEventId", timer.eit, event)
		if not(event):
			event = epgcache.lookupEventTime( timer.service_ref.ref, timer.begin + ((timer.end - timer.begin) /2) );
			log.debug("lookupEventTime", event )
		
		if event:
			if not ( len(timer.name) == len(event.getEventName()) ):
				msg = _("Skipping timer because it is already modified %s" % (timer.name) )
				log.info(msg)
				timer.log(602, "[SeriesPlugin]" + " " + msg )
				return
			begin = event.getBeginTime() or 0
			duration = event.getDuration() or 0
			end = begin + duration
			
		else:
			if config.plugins.seriesplugin.timer_eit_check.value:
				msg = _("Skipping timer because no event was found")
				log.info(msg, timer.name)
				timer.log(603, "[SeriesPlugin]" + " " + msg )
				return
			else:
				# We don't know the exact margins, we will assume the E2 default margins
				log.debug("We don't know the exact margins, we will assume the E2 default margins")
				begin = timer.begin + (config.recording.margin_before.value * 60)
				end = timer.end - (config.recording.margin_after.value * 60)
		
		
		timer.log(600, "[SeriesPlugin]" + " " + _("Try to find infos for %s" % (timer.name) ) )
		
		seriesPlugin = getInstance()
		
		if timer.service_ref:
			log.debug("getEpisode:", timer.name, timer.begin, timer.end, block)
			
			timer.sp_in_queue = True
			
			return seriesPlugin.getEpisode(
					boundFunction(self.timerCallback, timer),
					timer.name, begin, end, timer.service_ref, future=True, block=block
				)
		else:
			msg = _("Skipping lookup because no channel is specified")
			log.warning(msg)
			self.timerCallback(timer, msg)
			return None
Exemple #19
0
    def timerCallback(self, timer, data=None):
        splog("SPT: timerCallback", data)
        splog(data)

        if data and len(data) == 4 and timer:

            # Episode data available, refactor name and description
            #from SeriesPluginRenamer import newLegacyEncode
            timer.name = str(refactorTitle(timer.name, data))
            #timer.name = newLegacyEncode(refactorTitle(timer.name, data))
            timer.description = str(
                refactorDescription(timer.description, data))

            timer.log(
                610,
                "[SeriesPlugin] Success: Changed name: %s." % (timer.name))

        elif data:
            timer.log(611, "[SeriesPlugin] Failed: %s." % (str(data)))
            SeriesPluginTimer.data.append(str(timer.name) + " " + str(data))

        else:
            timer.log(612, "[SeriesPlugin] Failed.")
            SeriesPluginTimer.data.append(
                str(timer.name) + " " + _("No data available"))

        timer.sp_in_queue = False

        if config.plugins.seriesplugin.timer_popups.value or config.plugins.seriesplugin.timer_popups_success.value:

            SeriesPluginTimer.counter = SeriesPluginTimer.counter + 1

            if SeriesPluginTimer.data or config.plugins.seriesplugin.timer_popups_success.value:

                # Maybe there is a better way to avoid multiple Popups
                from SeriesPlugin import getInstance

                instance = getInstance()

                if instance.thread.empty() and instance.thread.finished():

                    if SeriesPluginTimer.data:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("Timer rename has been finished with %d errors:\n"
                              ) % (len(SeriesPluginTimer.data)) + "\n" +
                            "\n".join(SeriesPluginTimer.data),
                            MessageBox.TYPE_ERROR,
                            int(config.plugins.seriesplugin.
                                timer_popups_timeout.value),
                            'SP_PopUp_ID_TimerFinished')
                    else:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("%d timer renamed successfully") %
                            (SeriesPluginTimer.counter), MessageBox.TYPE_INFO,
                            int(config.plugins.seriesplugin.
                                timer_popups_timeout.value),
                            'SP_PopUp_ID_TimerFinished')
                    SeriesPluginTimer.data = []
                    SeriesPluginTimer.counter = 0

        return timer
    def getPage(self, url, use_proxy=True, counter=0):
        response = None

        logDebug("IB: getPage", url)

        cached = self.getCached(url)

        if cached:
            logDebug("IB: cached")
            response = cached

        else:
            logDebug("IB: not cached")

            try:
                from plugin import buildURL, USER_AGENT

                if use_proxy:
                    temp_url = buildURL(url)
                else:
                    temp_url = url

                req = Request(temp_url, headers={"User-Agent": USER_AGENT})
                response = urlopen(req, timeout=float(config.plugins.seriesplugin.socket_timeout.value)).read()

                if not response:
                    logDebug("IB: No data returned")

                    # logDebug("IB: response to cache: ", response)
                    # if response:
                    # 	self.doCachePage(url, response)

            except URLError as e:
                # For Python 2.6
                if counter > 2:
                    logDebug("IB: URLError counter > 2")
                    from SeriesPlugin import getInstance

                    instance = getInstance()
                    if instance:
                        instance.stop()
                    raise MyException("There was an URLError: %r" % e)
                elif hasattr(e, "code"):
                    logDebug("IB: URLError code", e.code, e.msg, counter)
                    sleep(2)
                    return self.getPage(url, use_proxy, counter + 1)
                else:
                    logDebug("IB: URLError else")
                    raise MyException("There was an URLError: %r" % e)

            except socket.timeout as e:
                # For Python 2.7
                if counter > 2:
                    logDebug("IB: URLError counter > 2")
                    from SeriesPlugin import getInstance

                    instance = getInstance()
                    if instance:
                        instance.stop()
                    raise MyException("There was an SocketTimeout: %r" % e)
                elif hasattr(e, "code"):
                    logDebug("IB: URLError code", e.code, e.msg, counter)
                    sleep(2)
                    return self.getPage(url, use_proxy, counter + 1)
                else:
                    logDebug("IB: URLError else")
                    raise MyException("There was an SocketTimeout: %r" % e)

        logDebug("IB: success")
        return response
	def __init__(self, session, service=None, event=None):
		if session:
			Screen.__init__(self, session)
			
			global instance
			instance = self
		
		self.session = session
		self.skinName = [ "SeriesPluginInfoScreen" ]
		
		self["logo"] = Pixmap()
		self["cover"] = Pixmap()
		self["state"] = Pixmap()
		
		self["event_title"] = Label()
		self["event_episode"] = Label()
		self["event_description"] = ScrollLabel()
		self["datetime"] = Label()
		self["channel"] = Label()
		self["duration"] = Label()
		
		self["key_red"] = Button("")				# Rename or Record
		self["key_green"] = Button("")			# Trakt Seen / Not Seen
		self["key_yellow"] = Button("")			# Show all Episodes of current season
		self["key_blue"] = Button("")				# Show all Seasons
		
		self.redButtonFunction = None
		
		#TODO HelpableActionMap
		self["actions"] = ActionMap(["OkCancelActions", "EventViewActions", "DirectionActions", "ColorActions"],
		{
			"cancel":    self.close,
			"ok":        self.close,
			"up":        self["event_description"].pageUp,
			"down":      self["event_description"].pageDown,
			"red":       self.redButton,
			"prevEvent": self.prevEpisode,
			"nextEvent": self.nextEpisode,
			
			#TODO
			#"pageUp":    self.pageUp,
			#"pageDown":  self.pageDown,
			#"openSimilarList": self.openSimilarList
		})
		
		log.info("SeriesPluginInfo:", service, event)
		self.service = service
		self.event = event
		
		self.name = ""
		self.short = ""
		self.data = None
		
		self.path = None
		self.eservice = None
		
		self.epg = eEPGCache.getInstance()
		self.serviceHandler = eServiceCenter.getInstance()
		self.seriesPlugin = getInstance()
		
		if session:
			self.onLayoutFinish.append( self.layoutFinished )
		else:
			self.getEpisode()
	def __init__(self, session):
		Screen.__init__(self, session)
		self.skinName = [ "SeriesPluginConfiguration" ]
		
		from plugin import NAME, VERSION
		self.setup_title = NAME + " " + _("Configuration") + " " + VERSION
		
		self.onChangedEntry = [ ]
		
		# Buttons
		self["key_red"] = Button(_("Cancel"))
		self["key_green"] = Button(_("OK"))
		self["key_blue"] = Button(_("Show Log"))
		self["key_yellow"] = Button(_("Channel Edit"))
		
		# Define Actions
		self["actions"] = ActionMap(["SetupActions", "ChannelSelectBaseActions", "ColorActions"],
		{
			"cancel":		self.keyCancel,
			"save":			self.keySave,
			"nextBouquet":	self.pageUp,
			"prevBouquet":	self.pageDown,
			"blue":			self.showLog,
			"yellow":		self.openChannelEditor,
			"ok": 			self.keyOK,
			"left": 		self.keyLeft,
			"right": 		self.keyRight,
		}, -2) # higher priority
		
		stopIndependent()
		#resetInstance()
		self.seriesPlugin = getInstance()
		
		# Create temporary identifier config elements
		identifiers = self.seriesPlugin.modules
		identifiers_elapsed = [k for k,v in identifiers.items() if v.knowsElapsed()]
		identifiers_today   = [k for k,v in identifiers.items() if v.knowsToday()]
		identifiers_future  = [k for k,v in identifiers.items() if v.knowsFuture()]
		self.cfg_identifier_elapsed = NoSave( ConfigSelection(choices = identifiers_elapsed, default = config.plugins.seriesplugin.identifier_elapsed.value or identifiers_elapsed[0]) )
		self.cfg_identifier_today   = NoSave( ConfigSelection(choices = identifiers_today,   default = config.plugins.seriesplugin.identifier_today.value   or identifiers_today[0]) )
		self.cfg_identifier_future  = NoSave( ConfigSelection(choices = identifiers_future,  default = config.plugins.seriesplugin.identifier_future.value  or identifiers_future[0]) )
		
		# Load patterns
		patterns = readPatternFile()
		self.cfg_pattern_title       = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_title.value ) )
		self.cfg_pattern_description = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_description.value ) )
		#self.cfg_pattern_record      = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_record.value ) )
		
		bouquetList = [("", "")]
		tvbouquets = getTVBouquets()
		for bouquet in tvbouquets:
			bouquetList.append((bouquet[1], bouquet[1]))
		self.cfg_bouquet_main = NoSave( ConfigSelection(choices = bouquetList,  default = config.plugins.seriesplugin.bouquet_main.value or str(list(zip(*bouquetList)[1]))   )  )
		
		checkList( self.cfg_pattern_title )
		checkList( self.cfg_pattern_description )
		checkList( self.cfg_bouquet_main )
		
		self.changesMade = False
		
		# Initialize Configuration
		self.list = []
		self.buildConfig()
		ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
		
		self.changed()
		self.onLayoutFinish.append(self.layoutFinished)
Exemple #23
0
    def __init__(self, timer, name, begin, end, block=False):

        splog("SPT: SeriesPluginTimer: name, timername, begin, end:", name,
              timer.name, begin, end)
        timer.log(600,
                  "[SeriesPlugin] Try to find infos for %s" % (timer.name))

        if block:
            return

        if hasattr(timer, 'sp_in_queue'):
            if timer.sp_in_queue:
                splog(
                    "SPT: SeriesPluginTimer: Skip timer is already in queue:",
                    timer.name)
                timer.log(
                    601, "[SeriesPlugin] Skip timer is already in queue %s" %
                    (timer.name))

        timer.sp_in_queue = True

        # We have to compare the length,
        # because of the E2 special chars handling for creating the filenames
        #if timer.name == name:
        # Mad Men != Mad_Men

        epgcache = eEPGCache.getInstance()

        event = None

        if timer.eit:
            #splog("SPT: Timer Eit is set", timer.service_ref.ref, timer.eit)
            event = epgcache.lookupEventId(timer.service_ref.ref, timer.eit)
            splog("SPT: LookupEventId", timer.eit, event)
        if not (event):
            #splog("Lookup EventTime", timer.service_ref.ref, end, begin)
            event = epgcache.lookupEventTime(timer.service_ref.ref,
                                             begin + ((end - begin) / 2))
            splog("SPT: lookupEventTime", event)
        #if not(event):
        #	splog("Lookup Event", timer.service_ref.ref, end, begin)
        #	events = epgcache.lookupEvent( [ "T" , ( timer.service_ref.ref, 0, begin + ((end - begin) /2) ) ] );
        #	splog("LookupEvent event(s) found", len(events), events )
        #	event = events and events[0]

        if event:
            #splog("EPG event found")
            if not (len(timer.name) == len(name) == len(event.getEventName())):
                splog("SPT: Skip timer because it is already modified",
                      timer.name, name, event and event.getEventName(),
                      len(timer.name), len(name), len(event.getEventName()))
                timer.log(
                    602,
                    "[SeriesPlugin] Skip timer because it is already modified")
                return
        else:
            if (len(timer.name) == len(name)):
                splog("SPT: Skip timer because no event was found", timer.name,
                      name, len(timer.name), len(name))
                timer.log(
                    603,
                    "[SeriesPlugin] Skip timer because no event was found")
                return

        if timer.begin < time() + 60:
            splog(
                "SPT: Skipping an event because it starts in less than 60 seconds",
                timer.name)
            timer.log(
                604,
                "[SeriesPlugin] Skip timer because it starts in less than 60 seconds"
            )
            return

        if timer.isRunning():
            splog("SPT: Skipping timer because it is already running",
                  timer.name)
            timer.log(
                605, "[SeriesPlugin] Skip timer because it is already running")
            return

        if timer.justplay:
            splog("SPT: Skipping justplay timer", timer.name)
            timer.log(606, "[SeriesPlugin] Skip justplay timer")
            return

        seriesPlugin = getInstance()

        if timer.service_ref:
            #channel = timer.service_ref.getServiceName()
            #splog(channel)

            splog("SPT: getEpisode:", name, begin, end, block)

            seriesPlugin.getEpisode(
                boundFunction(self.timerCallback, timer),
                #name, begin, end, channel, future=True
                name,
                begin,
                end,
                timer.service_ref,
                future=True)
        else:
            splog("SPT: SeriesPluginTimer: No channel specified")
            self.timerCallback("No channel specified")
	def getSeasonAndEpisode(self, timer, name, begin, end, block=True):
		
		logInfo("SeriesPluginTimer: timername, service, name, begin, end:", timer.name, str(timer.service_ref.ref), name, begin, end)
		
		if hasattr(timer, 'sp_in_queue'):
			if timer.sp_in_queue:
				logDebug("SPT: SeriesPluginTimer: Skip timer is already in queue:", timer.name)
				timer.log(601, "[SeriesPlugin] Skip timer is already in queue %s" % (timer.name) )
				return
		
		# We have to compare the length,
		# because of the E2 special chars handling for creating the filenames
		#if timer.name == name:
		# Mad Men != Mad_Men
		
		if TAG in timer.tags:
			logDebug("SPT: SeriesPluginTimer: Skip timer is already handled %s", timer.name)
			timer.log(607, "[SeriesPlugin] Skip timer is already handled %s" % (timer.name) )
			return
		
		if config.plugins.seriesplugin.timer_eit_check.value:
			
			event = None
			epgcache = eEPGCache.getInstance()
			
			if timer.eit:
				#logDebug("SPT: Timer Eit is set", timer.service_ref.ref, timer.eit)
				event = epgcache.lookupEventId(timer.service_ref.ref, timer.eit)
				logDebug("SPT: LookupEventId", timer.eit, event)
			if not(event):
				#logDebug("Lookup EventTime", timer.service_ref.ref, end, begin)
				event = epgcache.lookupEventTime( timer.service_ref.ref, begin + ((end - begin) /2) );
				logDebug("SPT: lookupEventTime", event )
			#if not(event):
			#	logDebug("Lookup Event", timer.service_ref.ref, end, begin)
			#	events = epgcache.lookupEvent( [ "T" , ( timer.service_ref.ref, 0, begin + ((end - begin) /2) ) ] );
			#	logDebug("LookupEvent event(s) found", len(events), events )
			#	event = events and events[0]
			
			if event:
				#logDebug("EPG event found")
				if not ( len(timer.name) == len(name) == len(event.getEventName()) ):
					logDebug("SPT: Skip timer because it is already modified", timer.name, name, event and event.getEventName(), len(timer.name), len(name), len(event.getEventName()) )
					timer.log(602, "[SeriesPlugin] Skip timer because it is already modified")
					return
			else:
				if ( len(timer.name) == len(name) ):
					logDebug("SPT: Skip timer because no event was found", timer.name, name, len(timer.name), len(name))
					timer.log(603, "[SeriesPlugin] Skip timer because no event was found")
					return
		
		if timer.begin < time() + 60:
			logDebug("SPT: Skipping timer because it starts in less than 60 seconds", timer.name )
			timer.log(604, "[SeriesPlugin] Skip timer because it starts in less than 60 seconds")
			return
		
		if timer.isRunning():
			logDebug("SPT: Skipping timer because it is already running", timer.name )
			timer.log(605, "[SeriesPlugin] Skip timer because it is already running")
			return
		
		if timer.justplay:
			logDebug("SPT: Skipping justplay timer", timer.name )
			timer.log(606, "[SeriesPlugin] Skip justplay timer")
			return
		
		timer.log(600, "[SeriesPlugin] Try to find infos for %s" % (timer.name) )
		
		seriesPlugin = getInstance()
		
		if timer.service_ref:
			#channel = timer.service_ref.getServiceName()
			#logDebug(channel)
			
			logDebug("SPT: getEpisode:", name, begin, end, block)
			
			timer.sp_in_queue = True
			
			if block:
				result = seriesPlugin.getEpisodeBlocking(
					name, begin, end, timer.service_ref, future=True
				)
				return self.timerCallback(timer, result)
			else:
				seriesPlugin.getEpisode(
					boundFunction(self.timerCallback, timer),
					#name, begin, end, channel, future=True
					name, begin, end, timer.service_ref, future=True
				)
				return None
		else:
			logDebug("SPT: SeriesPluginTimer: No channel specified")
			self.timerCallback(timer, "No channel specified")
			return None
	def __init__(self, timer, name, begin, end, block=False):
		
		splog("SPT: SeriesPluginTimer: name, timername, begin, end:", name, timer.name, begin, end)
		timer.log(600, "[SeriesPlugin] Try to find infos for %s" % (timer.name) )
		
		if block:
			return
		
		if hasattr(timer, 'sp_in_queue'):
			if timer.sp_in_queue:
				splog("SPT: SeriesPluginTimer: Skip timer is already in queue:", timer.name)
				timer.log(601, "[SeriesPlugin] Skip timer is already in queue %s" % (timer.name) )
		
		timer.sp_in_queue = True
		
		# We have to compare the length,
		# because of the E2 special chars handling for creating the filenames
		#if timer.name == name:
		# Mad Men != Mad_Men
		
		epgcache = eEPGCache.getInstance()
		
		event = None
		
		if timer.eit:
			#splog("SPT: Timer Eit is set", timer.service_ref.ref, timer.eit)
			event = epgcache.lookupEventId(timer.service_ref.ref, timer.eit)
			splog("SPT: LookupEventId", timer.eit, event)
		if not(event):
			#splog("Lookup EventTime", timer.service_ref.ref, end, begin)
			event = epgcache.lookupEventTime( timer.service_ref.ref, begin + ((end - begin) /2) );
			splog("SPT: lookupEventTime", event )
		#if not(event):
		#	splog("Lookup Event", timer.service_ref.ref, end, begin)
		#	events = epgcache.lookupEvent( [ "T" , ( timer.service_ref.ref, 0, begin + ((end - begin) /2) ) ] );
		#	splog("LookupEvent event(s) found", len(events), events )
		#	event = events and events[0]
		
		if event:
			#splog("EPG event found")
			if not ( len(timer.name) == len(name) == len(event.getEventName()) ):
				splog("SPT: Skip timer because it is already modified", timer.name, name, event and event.getEventName(), len(timer.name), len(name), len(event.getEventName()) )
				timer.log(602, "[SeriesPlugin] Skip timer because it is already modified")
				return
		else:
			if ( len(timer.name) == len(name) ):
				splog("SPT: Skip timer because no event was found", timer.name, name, len(timer.name), len(name))
				timer.log(603, "[SeriesPlugin] Skip timer because no event was found")
				return
		
		if timer.begin < time() + 60:
			splog("SPT: Skipping an event because it starts in less than 60 seconds", timer.name )
			timer.log(604, "[SeriesPlugin] Skip timer because it starts in less than 60 seconds")
			return
		
		if timer.isRunning():
			splog("SPT: Skipping timer because it is already running", timer.name )
			timer.log(605, "[SeriesPlugin] Skip timer because it is already running")
			return
		
		if timer.justplay:
			splog("SPT: Skipping justplay timer", timer.name )
			timer.log(606, "[SeriesPlugin] Skip justplay timer")
			return
		
		
		seriesPlugin = getInstance()
		
		
		if timer.service_ref:
			#channel = timer.service_ref.getServiceName()
			#splog(channel)
			
			splog("SPT: getEpisode:", name, begin, end, block)
			
			seriesPlugin.getEpisode(
				boundFunction(self.timerCallback, timer),
				#name, begin, end, channel, future=True
				name, begin, end, timer.service_ref, future=True
			)
		else:
			splog("SPT: SeriesPluginTimer: No channel specified")
			self.timerCallback("No channel specified")
    def getPage(self, url, use_proxy=True, counter=0):
        response = None

        logDebug("IB: getPage", url)

        cached = self.getCached(url)

        if cached:
            logDebug("IB: cached")
            response = cached

        else:
            logDebug("IB: not cached")

            try:
                from plugin import buildURL, USER_AGENT

                if use_proxy:
                    temp_url = buildURL(url)
                else:
                    temp_url = url

                req = Request(temp_url, headers={'User-Agent': USER_AGENT})
                response = urlopen(req,
                                   timeout=float(config.plugins.seriesplugin.
                                                 socket_timeout.value)).read()

                if not response:
                    logDebug("IB: No data returned")

                #logDebug("IB: response to cache: ", response)
                #if response:
                #	self.doCachePage(url, response)

            except URLError as e:
                # For Python 2.6
                if counter > 2:
                    logDebug("IB: URLError counter > 2")
                    from SeriesPlugin import getInstance
                    instance = getInstance()
                    if instance:
                        instance.stop()
                    raise MyException("There was an URLError: %r" % e)
                elif hasattr(e, "code"):
                    logDebug("IB: URLError code", e.code, e.msg, counter)
                    sleep(2)
                    return self.getPage(url, use_proxy, counter + 1)
                else:
                    logDebug("IB: URLError else")
                    raise MyException("There was an URLError: %r" % e)

            except socket.timeout as e:
                # For Python 2.7
                if counter > 2:
                    logDebug("IB: URLError counter > 2")
                    from SeriesPlugin import getInstance
                    instance = getInstance()
                    if instance:
                        instance.stop()
                    raise MyException("There was an SocketTimeout: %r" % e)
                elif hasattr(e, "code"):
                    logDebug("IB: URLError code", e.code, e.msg, counter)
                    sleep(2)
                    return self.getPage(url, use_proxy, counter + 1)
                else:
                    logDebug("IB: URLError else")
                    raise MyException("There was an SocketTimeout: %r" % e)

        logDebug("IB: success")
        return response