コード例 #1
0
    def getScheduleEntry(self):
        # Get the current time that we are checking the schedule for
        localTime = time.localtime()
        currentTime = (localTime.tm_hour * 60) + localTime.tm_min

        # Get the current day of the week
        # 0 = Monday 6 = Sunday
        today = localTime.tm_wday
        # Make sure that the day returned is within our expected list
        if today not in Settings.DAY_TYPE:
            log("Schedule: Unknown day today %d, setting to everyday" % today)
            today = Settings.EVERY_DAY

        # Check if we need to refresh the schedule details from the file
        # in case they have changed
        if Settings.getScheduleSetting() == Settings.SCHEDULE_FILE:
            # Check if the file has changed
            scheduleFileName = Settings.getScheduleFile()
            if scheduleFileName not in [None, ""]:
                if xbmcvfs.exists(scheduleFileName):
                    statFile = xbmcvfs.Stat(scheduleFileName)
                    modified = statFile.st_mtime()
                    if modified != self.lastScheduleModified:
                        log("Schedule: Schedule file has changed (%s)" % str(modified))
                        # We use the offset to work out if the data has changed
                        if self.idOffset > 0:
                            self.idOffset = 0
                        else:
                            self.idOffset = 1000
                        # Clear the existing schedule items
                        self.scheduleDetails = []
                        # Load the new schedule items
                        self._loadFromFile()

        # Check the scheduled items to see if any cover the current time
        for item in self.scheduleDetails:
            if (item['start'] <= currentTime) and (item['end'] >= currentTime):
                # Make sure this is for the current day
                if (today == Settings.EVERY_DAY) or (item['day'] in [Settings.EVERY_DAY, today]):
                    return item['id']
            # Check for the case where the time laps over midnight
            if item['start'] > item['end']:
                if (currentTime >= item['start']) or (currentTime <= item['end']):
                    # Check to see if we are restricting to day
                    if (today == Settings.EVERY_DAY) or (item['day'] == Settings.EVERY_DAY):
                        return item['id']
                    else:
                        if (currentTime >= item['start']) and (item['day'] in [Settings.EVERY_DAY, today]):
                            return item['id']
                        else:
                            # The day is set for the start of the time interval
                            # so if we go over to the next day we need to update
                            # what the expected day is
                            nextDay = Settings.getNextDay(item['day'])
                            if (currentTime <= item['end']) and (item['day'] in [Settings.EVERY_DAY, nextDay]):
                                return item['id']
        return -1
コード例 #2
0
    def _loadFromFile(self):
        # Get the videos schedule that is stored in the file
        scheduleFileName = Settings.getScheduleFile()
        if scheduleFileName in [None, ""]:
            log("Schedule: No schedule file set")
            return

        log("Schedule: Searching for schedule file: %s" % scheduleFileName)

        # Return False if file does not exist
        if not xbmcvfs.exists(scheduleFileName):
            log("Schedule: No schedule file found: %s" % scheduleFileName)
            return

        # Save off the time this file was modified
        statFile = xbmcvfs.Stat(scheduleFileName)
        self.lastScheduleModified = statFile.st_mtime()
        log("Schedule: Reading in schedule file with modify time: %s" % str(self.lastScheduleModified))

        # The file exists, so start loading it
        try:
            # Need to first load the contents of the file into
            # a string, this is because the XML File Parse option will
            # not handle formats like smb://
            scheduleFile = xbmcvfs.File(scheduleFileName, 'r')
            scheduleFileStr = scheduleFile.read()
            scheduleFile.close()

            # Create an XML parser
            scheduleXml = ET.ElementTree(ET.fromstring(scheduleFileStr))
            rootElement = scheduleXml.getroot()

            log("Schedule: Root element is = %s" % rootElement.tag)

            # Check which format if being used
            if rootElement.tag == "schedule":
                log("Schedule: Schedule format file detected")
                #    <schedule>
                #        <rule start="14:24" end="14:37" video="video3.mkv" overlay="WindowFrame1.png" />
                #    </schedule>

                # Get the directory that the schedule file is in as this might be needed
                # if we have local paths in the XML file
                directory = os_path_split(scheduleFileName)[0]

                # There could be multiple rule entries, so loop through all of them
                itemNum = self.idOffset + 1
                for ruleElem in scheduleXml.findall('rule'):
                    if ruleElem is not None:
                        videoFile = ruleElem.get('video', None)
                        overlayFile = ruleElem.get('overlay', None)
                        startTime = self._convertTimeToMinutes(ruleElem.get('start', "00:00"))
                        endTime = self._convertTimeToMinutes(ruleElem.get('end', "00:00"))
                        day = self._convertDayFormat(ruleElem.get('day', None))

                    if (videoFile not in [None, ""]) and (startTime not in [None, ""]) and (endTime not in [None, ""]):
                        # Make it a full path if it is not already
                        if videoFile.startswith('..') or (("/" not in videoFile) and ("\\" not in videoFile)):
                            videoFile = os_path_join(directory, videoFile)
                        if overlayFile not in [None, ""]:
                            if overlayFile.startswith('..') or (("/" not in overlayFile) and ("\\" not in overlayFile)):
                                overlayFile = os_path_join(directory, overlayFile)
                        log("Schedule File: Item %d (Start:%d, End:%d) contains video %s" % (itemNum, startTime, endTime, videoFile))

                        # Check if the video file exists
                        if os_path_isfile(videoFile):
                            details = {'id': itemNum, 'start': startTime, 'end': endTime, 'day': day, 'video': videoFile, 'overlay': overlayFile}
                            self.scheduleDetails.append(details)
                        else:
                            log("Schedule: File does not exist: %s" % videoFile)

                        itemNum = itemNum + 1
            else:
                log("Schedule: Unknown schedule file format")

            del scheduleXml
        except:
            log("Schedule: Failed to process schedule file: %s" % scheduleFileName, xbmc.LOGERROR)
            log("Schedule: %s" % traceback.format_exc(), xbmc.LOGERROR)
コード例 #3
0
    def _loadFromFile(self):
        # Get the videos schedule that is stored in the file
        scheduleFileName = Settings.getScheduleFile()
        if scheduleFileName in [None, ""]:
            log("Schedule: No schedule file set")
            return

        log("Schedule: Searching for schedule file: %s" % scheduleFileName)

        # Return False if file does not exist
        if not xbmcvfs.exists(scheduleFileName):
            log("Schedule: No schedule file found: %s" % scheduleFileName)
            return

        # Save off the time this file was modified
        statFile = xbmcvfs.Stat(scheduleFileName)
        self.lastScheduleModified = statFile.st_mtime()
        log("Schedule: Reading in schedule file with modify time: %s" %
            str(self.lastScheduleModified))

        # The file exists, so start loading it
        try:
            # Need to first load the contents of the file into
            # a string, this is because the XML File Parse option will
            # not handle formats like smb://
            scheduleFile = xbmcvfs.File(scheduleFileName, 'r')
            scheduleFileStr = scheduleFile.read()
            scheduleFile.close()

            # Create an XML parser
            scheduleXml = ET.ElementTree(ET.fromstring(scheduleFileStr))
            rootElement = scheduleXml.getroot()

            log("Schedule: Root element is = %s" % rootElement.tag)

            # Check which format if being used
            if rootElement.tag == "schedule":
                log("Schedule: Schedule format file detected")
                #    <schedule>
                #        <rule start="14:24" end="14:37" video="video3.mkv" overlay="WindowFrame1.png" />
                #    </schedule>

                # Get the directory that the schedule file is in as this might be needed
                # if we have local paths in the XML file
                directory = os_path_split(scheduleFileName)[0]

                # There could be multiple rule entries, so loop through all of them
                itemNum = self.idOffset + 1
                for ruleElem in scheduleXml.findall('rule'):
                    if ruleElem is not None:
                        videoFile = ruleElem.get('video', None)
                        overlayFile = ruleElem.get('overlay', None)
                        startTime = self._convertTimeToMinutes(
                            ruleElem.get('start', "00:00"))
                        endTime = self._convertTimeToMinutes(
                            ruleElem.get('end', "00:00"))
                        day = self._convertDayFormat(ruleElem.get('day', None))

                    if (videoFile not in [None, ""]) and (startTime not in [
                            None, ""
                    ]) and (endTime not in [None, ""]):
                        # Make it a full path if it is not already
                        if videoFile.startswith('..') or (
                            ("/" not in videoFile) and
                            ("\\" not in videoFile)):
                            videoFile = os_path_join(directory, videoFile)
                        if overlayFile not in [None, ""]:
                            if overlayFile.startswith('..') or (
                                ("/" not in overlayFile) and
                                ("\\" not in overlayFile)):
                                overlayFile = os_path_join(
                                    directory, overlayFile)
                        log("Schedule File: Item %d (Start:%d, End:%d) contains video %s"
                            % (itemNum, startTime, endTime, videoFile))

                        # Check if the video file exists
                        if os_path_isfile(videoFile):
                            details = {
                                'id': itemNum,
                                'start': startTime,
                                'end': endTime,
                                'day': day,
                                'video': videoFile,
                                'overlay': overlayFile
                            }
                            self.scheduleDetails.append(details)
                        else:
                            log("Schedule: File does not exist: %s" %
                                videoFile)

                        itemNum = itemNum + 1
            else:
                log("Schedule: Unknown schedule file format")

            del scheduleXml
        except:
            log(
                "Schedule: Failed to process schedule file: %s" %
                scheduleFileName, xbmc.LOGERROR)
            log("Schedule: %s" % traceback.format_exc(), xbmc.LOGERROR)
コード例 #4
0
    def getScheduleEntry(self):
        # Get the current time that we are checking the schedule for
        localTime = time.localtime()
        currentTime = (localTime.tm_hour * 60) + localTime.tm_min

        # Get the current day of the week
        # 0 = Monday 6 = Sunday
        today = localTime.tm_wday
        # Make sure that the day returned is within our expected list
        if today not in Settings.DAY_TYPE:
            log("Schedule: Unknown day today %d, setting to everyday" % today)
            today = Settings.EVERY_DAY

        # Check if we need to refresh the schedule details from the file
        # in case they have changed
        if Settings.getScheduleSetting() == Settings.SCHEDULE_FILE:
            # Check if the file has changed
            scheduleFileName = Settings.getScheduleFile()
            if scheduleFileName not in [None, ""]:
                if xbmcvfs.exists(scheduleFileName):
                    statFile = xbmcvfs.Stat(scheduleFileName)
                    modified = statFile.st_mtime()
                    if modified != self.lastScheduleModified:
                        log("Schedule: Schedule file has changed (%s)" %
                            str(modified))
                        # We use the offset to work out if the data has changed
                        if self.idOffset > 0:
                            self.idOffset = 0
                        else:
                            self.idOffset = 1000
                        # Clear the existing schedule items
                        self.scheduleDetails = []
                        # Load the new schedule items
                        self._loadFromFile()

        # Check the scheduled items to see if any cover the current time
        for item in self.scheduleDetails:
            if (item['start'] <= currentTime) and (item['end'] >= currentTime):
                # Make sure this is for the current day
                if (today == Settings.EVERY_DAY) or (item['day'] in [
                        Settings.EVERY_DAY, today
                ]):
                    return item['id']
            # Check for the case where the time laps over midnight
            if item['start'] > item['end']:
                if (currentTime >= item['start']) or (currentTime <=
                                                      item['end']):
                    # Check to see if we are restricting to day
                    if (today
                            == Settings.EVERY_DAY) or (item['day']
                                                       == Settings.EVERY_DAY):
                        return item['id']
                    else:
                        if (currentTime >= item['start']) and (item['day'] in [
                                Settings.EVERY_DAY, today
                        ]):
                            return item['id']
                        else:
                            # The day is set for the start of the time interval
                            # so if we go over to the next day we need to update
                            # what the expected day is
                            nextDay = Settings.getNextDay(item['day'])
                            if (currentTime <= item['end']) and (
                                    item['day']
                                    in [Settings.EVERY_DAY, nextDay]):
                                return item['id']
        return -1