Exemplo n.º 1
0
    def generateServicelist(self, services, bouquets):
        # This will hold services which are not explicitely in our list
        additionalServices = []
        additionalBouquets = []

        # See if we are supposed to read in autotimer services
        if config.plugins.epgrefresh.inherit_autotimer.value:
            removeInstance = False
            try:
                # Import Instance
                from Plugins.Extensions.AutoTimer.plugin import autotimer

                if autotimer is None:
                    removeInstance = True
                    # Create an instance
                    from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
                    autotimer = AutoTimer()

                # Read in configuration
                autotimer.readXml()
            except Exception as e:
                print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
            else:
                # Fetch services
                for timer in autotimer.getEnabledTimerList():
                    additionalServices.extend(
                        [EPGRefreshService(x, None) for x in timer.services])
                    additionalBouquets.extend(
                        [EPGRefreshService(x, None) for x in timer.bouquets])
            finally:
                # Remove instance if there wasn't one before
                if removeInstance:
                    autotimer = None

        scanServices = []
        channelIdList = []
        self.addServices(services, scanServices, channelIdList)

        serviceHandler = eServiceCenter.getInstance()
        for bouquet in bouquets.union(additionalBouquets):
            myref = eServiceReference(bouquet.sref)
            list = serviceHandler.list(myref)
            if list is not None:
                while 1:
                    s = list.getNext()
                    # TODO: I wonder if its sane to assume we get services here (and not just new lists)
                    if s.valid():
                        additionalServices.append(
                            EPGRefreshService(s.toString(), None))
                    else:
                        break
        del additionalBouquets[:]

        self.addServices(additionalServices, scanServices, channelIdList)
        del additionalServices[:]

        return scanServices
Exemplo n.º 2
0
    def generateServicelist(self, services, bouquets):
        additionalServices = []
        additionalBouquets = []
        if config.plugins.epgrefresh.inherit_autotimer.value:
            try:
                from Plugins.Extensions.AutoTimer.plugin import autotimer
                if autotimer is None:
                    from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
                    autotimer = AutoTimer()
                autotimer.readXml()
            except Exception as e:
                print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
            else:
                for timer in autotimer.getEnabledTimerList():
                    additionalServices.extend(
                        [EPGRefreshService(x, None) for x in timer.services])
                    additionalBouquets.extend(
                        [EPGRefreshService(x, None) for x in timer.bouquets])
        scanServices = []
        channelIdList = []
        self.addServices(services, scanServices, channelIdList)
        serviceHandler = eServiceCenter.getInstance()
        for bouquet in bouquets.union(additionalBouquets):
            myref = eServiceReference(bouquet.sref)
            list = serviceHandler.list(myref)
            if list is not None:
                while 1:
                    s = list.getNext()
                    if s and s.valid() and s.type == eServiceReference.idDVB:
                        additionalServices.append(
                            EPGRefreshService(s.toString(), None))
                    else:
                        break
        del additionalBouquets[:]

        def sortServices(services):  # sort by positions - better for motor
            unsortedServices = []
            for service in services:
                ref = service.sref
                position = ref.split(":")[6][:-4]
                if not position:
                    position = "0"
                auxiliarySortParameter = int(position, 16)
                if auxiliarySortParameter > 1800:
                    auxiliarySortParameter = 3600 - auxiliarySortParameter
                unsortedServices.append((auxiliarySortParameter, service))
            unsortedServices.sort()
            sortedServices = []
            for service in unsortedServices:
                sortedServices.append(service[1])
            return sortedServices

        self.addServices(additionalServices, scanServices, channelIdList)
        scanServices = sortServices(scanServices)
        del additionalServices[:]
        return scanServices
Exemplo n.º 3
0
    def generateServicelist(self, services, bouquets):
        # This will hold services which are not explicitely in our list
        additionalServices = []
        additionalBouquets = []

        # See if we are supposed to read in autotimer services
        if config.plugins.epgrefresh.inherit_autotimer.value:
            removeInstance = False
            try:
                # Import Instance
                from Plugins.Extensions.AutoTimer.plugin import autotimer

                if autotimer is None:
                    removeInstance = True
                    # Create an instance
                    from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer

                    autotimer = AutoTimer()

                    # Read in configuration
                autotimer.readXml()
            except Exception as e:
                print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
            else:
                # Fetch services
                for timer in autotimer.getEnabledTimerList():
                    additionalServices.extend([EPGRefreshService(x, None) for x in timer.services])
                    additionalBouquets.extend([EPGRefreshService(x, None) for x in timer.bouquets])
            finally:
                # Remove instance if there wasn't one before
                if removeInstance:
                    autotimer = None

        scanServices = []
        channelIdList = []
        self.addServices(services, scanServices, channelIdList)

        serviceHandler = eServiceCenter.getInstance()
        for bouquet in bouquets.union(additionalBouquets):
            myref = eServiceReference(bouquet.sref)
            list = serviceHandler.list(myref)
            if list is not None:
                while 1:
                    s = list.getNext()
                    # TODO: I wonder if its sane to assume we get services here (and not just new lists)
                    if s.valid():
                        additionalServices.append(EPGRefreshService(s.toString(), None))
                    else:
                        break
        del additionalBouquets[:]

        self.addServices(additionalServices, scanServices, channelIdList)
        del additionalServices[:]

        return scanServices
Exemplo n.º 4
0
	def generateServicelist(self, services, bouquets):
		additionalServices = []
		additionalBouquets = []
		if config.plugins.epgrefresh.inherit_autotimer.value:
			try:
				from Plugins.Extensions.AutoTimer.plugin import autotimer
				if autotimer is None:
					from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
					autotimer = AutoTimer()
				autotimer.readXml()
			except Exception as e:
				print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
			else:
				for timer in autotimer.getEnabledTimerList():
					additionalServices.extend([EPGRefreshService(x, None) for x in timer.services])
					additionalBouquets.extend([EPGRefreshService(x, None) for x in timer.bouquets])
		scanServices = []
		channelIdList = []
		self.addServices(services, scanServices, channelIdList)
		serviceHandler = eServiceCenter.getInstance()
		for bouquet in bouquets.union(additionalBouquets):
			myref = eServiceReference(bouquet.sref)
			list = serviceHandler.list(myref)
			if list is not None:
				while 1:
					s = list.getNext()
					if s and s.valid() and s.type == eServiceReference.idDVB:
						additionalServices.append(EPGRefreshService(s.toString(), None))
					else:
						break
		del additionalBouquets[:]
		def sortServices(services): # sort by positions - better for motor
			unsortedServices = []
			for service in services:
				ref = service.sref
				position = ref.split(":")[6][:-4]
				if not position:
					position = "0"
				auxiliarySortParameter = int(position, 16)
				if auxiliarySortParameter > 1800:
					auxiliarySortParameter = 3600 - auxiliarySortParameter
				unsortedServices.append((auxiliarySortParameter, service))
			unsortedServices.sort()
			sortedServices = []
			for service in unsortedServices:
				sortedServices.append(service[1])
			return sortedServices
		self.addServices(additionalServices, scanServices, channelIdList)
		scanServices = sortServices(scanServices)
		del additionalServices[:]
		return scanServices
Exemplo n.º 5
0
class EPGRefresh:
    """Simple Class to refresh EPGData"""
    def __init__(self):
        # Initialize
        self.services = (set(), set())
        self.previousService = None
        self.forcedScan = False
        self.session = None
        self.beginOfTimespan = 0

        # Mtime of configuration files
        self.configMtime = -1

        # Read in Configuration
        self.readConfiguration()

    def readConfiguration(self):
        # Check if file exists
        if not path.exists(CONFIG):
            return

        # Check if file did not change
        mtime = path.getmtime(CONFIG)
        if mtime == self.configMtime:
            return

        # Keep mtime
        self.configMtime = mtime

        # Empty out list
        self.services[0].clear()
        self.services[1].clear()

        # Open file
        configuration = cet_parse(CONFIG).getroot()

        # Add References
        for service in configuration.findall("service"):
            value = service.text
            if value:
                # strip all after last : (custom name)
                pos = value.rfind(':')
                if pos != -1:
                    value = value[:pos + 1]

                duration = service.get('duration', None)
                duration = duration and int(duration)

                self.services[0].add(EPGRefreshService(value, duration))
        for bouquet in configuration.findall("bouquet"):
            value = bouquet.text
            if value:
                duration = bouquet.get('duration', None)
                duration = duration and int(duration)
                self.services[1].add(EPGRefreshService(value, duration))

    def buildConfiguration(self, webif=False):
        list = ['<?xml version="1.0" ?>\n<epgrefresh>\n\n']

        if webif:
            TAGSERVICE = 'e2servicereference'
            TAGBOUQUET = 'e2servicereference'
            TAGNAME = 'e2servicename'
        else:
            TAGSERVICE = 'service'
            TAGBOUQUET = 'bouquet'
            TAGNAME = '!--'

        for service in self.services[0]:
            ref = ServiceReference(service.sref)
            list.extend((' <', TAGNAME, '>',
                         stringToXML(ref.getServiceName().replace(
                             '\xc2\x86',
                             '').replace('\xc2\x87',
                                         '')), '</', TAGNAME, '>\n'))
            list.extend((' <', TAGSERVICE))
            if service.duration is not None:
                list.extend((' duration="', str(service.duration), '"'))
            list.extend(
                ('>', stringToXML(service.sref), '</', TAGSERVICE, '>\n'))
        for bouquet in self.services[1]:
            ref = ServiceReference(bouquet.sref)
            list.extend((' <', TAGNAME, '>',
                         stringToXML(ref.getServiceName().replace(
                             '\xc2\x86',
                             '').replace('\xc2\x87',
                                         '')), '</', TAGNAME, '>\n'))
            list.extend((' <', TAGBOUQUET))
            if bouquet.duration is not None:
                list.extend((' duration="', str(bouquet.duration), '"'))
            list.extend(
                ('>', stringToXML(bouquet.sref), '</', TAGBOUQUET, '>\n'))

        list.append('\n</epgrefresh>')

        return list

    def saveConfiguration(self):
        file = open(CONFIG, 'w')
        file.writelines(self.buildConfiguration())

        file.close()

    def forceRefresh(self, session=None):
        print "[EPGRefresh] Forcing start of EPGRefresh"
        if self.session is None:
            if session is not None:
                self.session = session
            else:
                return False

        self.forcedScan = True
        self.prepareRefresh()
        return True

    def start(self, session=None):
        if session is not None:
            self.session = session

        epgrefreshtimer.setRefreshTimer(self.createWaitTimer)

    def stop(self):
        print "[EPGRefresh] Stopping Timer"
        epgrefreshtimer.clear()

    def prepareRefresh(self):
        print "[EPGRefresh] About to start refreshing EPG"

        # Keep service
        self.previousService = self.session.nav.getCurrentlyPlayingServiceReference(
        )

        # Maybe read in configuration
        try:
            self.readConfiguration()
        except Exception, e:
            print "[EPGRefresh] Error occured while reading in configuration:", e

        # This will hold services which are not explicitely in our list
        additionalServices = []
        additionalBouquets = []

        # See if we are supposed to read in autotimer services
        if config.plugins.epgrefresh.inherit_autotimer.value:
            removeInstance = False
            try:
                # Import Instance
                from Plugins.Extensions.AutoTimer.plugin import autotimer

                if autotimer is None:
                    removeInstance = True
                    # Create an instance
                    from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
                    autotimer = AutoTimer()

                # Read in configuration
                autotimer.readXml()
            except Exception, e:
                print "[EPGRefresh] Could not inherit AutoTimer Services:", e
            else:
                # Fetch services
                for timer in autotimer.getEnabledTimerList():
                    additionalServices.extend(
                        [EPGRefreshService(x, None) for x in timer.services])
                    additionalBouquets.extend(
                        [EPGRefreshService(x, None) for x in timer.bouquets])
            finally:
Exemplo n.º 6
0
	def prepareRefresh(self):
		print("[EPGRefresh] About to start refreshing EPG")

		# Maybe read in configuration
		try:
			self.readConfiguration()
		except Exception as e:
			print("[EPGRefresh] Error occured while reading in configuration:", e)

		# This will hold services which are not explicitely in our list
		additionalServices = []
		additionalBouquets = []

		# See if we are supposed to read in autotimer services
		if config.plugins.epgrefresh.inherit_autotimer.value:
			removeInstance = False
			try:
				# Import Instance
				from Plugins.Extensions.AutoTimer.plugin import autotimer

				if autotimer is None:
					removeInstance = True
					# Create an instance
					from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
					autotimer = AutoTimer()

				# Read in configuration
				autotimer.readXml()
			except Exception as e:
				print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
			else:
				# Fetch services
				for timer in autotimer.getEnabledTimerList():
					additionalServices.extend([EPGRefreshService(x, None) for x in timer.services])
					additionalBouquets.extend([EPGRefreshService(x, None) for x in timer.bouquets])
			finally:
				# Remove instance if there wasn't one before
				if removeInstance:
					autotimer = None

		serviceHandler = eServiceCenter.getInstance()
		for bouquet in self.services[1].union(additionalBouquets):
			myref = eServiceReference(bouquet.sref)
			list = serviceHandler.list(myref)
			if list is not None:
				while 1:
					s = list.getNext()
					# TODO: I wonder if its sane to assume we get services here (and not just new lists)
					if s.valid():
						additionalServices.append(EPGRefreshService(s.toString(), None))
					else:
						break
		del additionalBouquets[:]

		scanServices = []
		channelIdList = []
		for scanservice in self.services[0].union(additionalServices):
			service = eServiceReference(scanservice.sref)
			if not service.valid() \
				or (service.flags & (eServiceReference.isMarker|eServiceReference.isDirectory)):

				continue

			channelID = '%08x%04x%04x' % (
				service.getUnsignedData(4), # NAMESPACE
				service.getUnsignedData(2), # TSID
				service.getUnsignedData(3), # ONID
			)

			if channelID not in channelIdList:
				scanServices.append(scanservice)
				channelIdList.append(channelID)
		del additionalServices[:]

		# Debug
		print("[EPGRefresh] Services we're going to scan:", ', '.join([repr(x) for x in scanServices]))

		self.maybeStopAdapter()
		# NOTE: start notification is handled in adapter initializer
		if config.plugins.epgrefresh.adapter.value.startswith("pip"):
			hidden = config.plugins.epgrefresh.adapter.value == "pip_hidden"
			refreshAdapter = PipAdapter(self.session, hide=hidden)
		elif config.plugins.epgrefresh.adapter.value.startswith("record"):
			refreshAdapter = RecordAdapter(self.session)
		else:
			refreshAdapter = MainPictureAdapter(self.session)

		if (not refreshAdapter.backgroundCapable and Screens.Standby.inStandby) or not refreshAdapter.prepare():
			print("[EPGRefresh] Adapter is not able to run in background or not available, falling back to MainPictureAdapter")
			refreshAdapter = MainPictureAdapter(self.session)
			refreshAdapter.prepare()
		self.refreshAdapter = refreshAdapter

		self.scanServices = scanServices
		self.refresh()
Exemplo n.º 7
0
    def prepareRefresh(self):
        print("[EPGRefresh] About to start refreshing EPG")

        # Maybe read in configuration
        try:
            self.readConfiguration()
        except Exception as e:
            print("[EPGRefresh] Error occured while reading in configuration:",
                  e)

        # This will hold services which are not explicitely in our list
        additionalServices = []
        additionalBouquets = []

        # See if we are supposed to read in autotimer services
        if config.plugins.epgrefresh.inherit_autotimer.value:
            removeInstance = False
            try:
                # Import Instance
                from Plugins.Extensions.AutoTimer.plugin import autotimer

                if autotimer is None:
                    removeInstance = True
                    # Create an instance
                    from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
                    autotimer = AutoTimer()

                # Read in configuration
                autotimer.readXml()
            except Exception as e:
                print("[EPGRefresh] Could not inherit AutoTimer Services:", e)
            else:
                # Fetch services
                for timer in autotimer.getEnabledTimerList():
                    additionalServices.extend(
                        [EPGRefreshService(x, None) for x in timer.services])
                    additionalBouquets.extend(
                        [EPGRefreshService(x, None) for x in timer.bouquets])
            finally:
                # Remove instance if there wasn't one before
                if removeInstance:
                    autotimer = None

        scanServices = []
        channelIdList = []
        self.addServices(self.services[0], scanServices, channelIdList)

        serviceHandler = eServiceCenter.getInstance()
        for bouquet in self.services[1].union(additionalBouquets):
            myref = eServiceReference(bouquet.sref)
            list = serviceHandler.list(myref)
            if list is not None:
                while 1:
                    s = list.getNext()
                    # TODO: I wonder if its sane to assume we get services here (and not just new lists)
                    if s.valid():
                        additionalServices.append(
                            EPGRefreshService(s.toString(), None))
                    else:
                        break
        del additionalBouquets[:]

        self.addServices(additionalServices, scanServices, channelIdList)
        del additionalServices[:]

        # Debug
        print("[EPGRefresh] Services we're going to scan:",
              ', '.join([repr(x) for x in scanServices]))

        self.maybeStopAdapter()
        # NOTE: start notification is handled in adapter initializer
        if config.plugins.epgrefresh.adapter.value.startswith("pip"):
            hidden = config.plugins.epgrefresh.adapter.value == "pip_hidden"
            refreshAdapter = PipAdapter(self.session, hide=hidden)
        elif config.plugins.epgrefresh.adapter.value.startswith("record"):
            refreshAdapter = RecordAdapter(self.session)
        else:
            refreshAdapter = MainPictureAdapter(self.session)

        if (not refreshAdapter.backgroundCapable
                and Screens.Standby.inStandby) or not refreshAdapter.prepare():
            print(
                "[EPGRefresh] Adapter is not able to run in background or not available, falling back to MainPictureAdapter"
            )
            refreshAdapter = MainPictureAdapter(self.session)
            refreshAdapter.prepare()
        self.refreshAdapter = refreshAdapter

        self.scanServices = scanServices
        self.refresh()