예제 #1
0
    def addScheduledShow(self, channelList, channeldata, appending):
        self.log("addScheduledShow")
        chan = 0
        epcount = 0
        startingep = 0
        curchan = channeldata.channelNumber
        curruleid = self.getRuleIndex(channeldata)
        currentchantime = channelList.lastExitTime + channeldata.totalTimePlayed

        if channeldata.Playlist.size() == 0:
            return False

        try:
            chan = int(self.optionValues[0])
            epcount = int(self.optionValues[3])
            startingep = int(self.optionValues[4]) - 1
        except:
            pass

        if startingep < 0:
            startingep = 0

        # If the next scheduled show has already passed, then skip it
        if currentchantime > self.nextScheduledTime:
            thedate = datetime.datetime.fromtimestamp(self.nextScheduledTime)
            delta = datetime.timedelta(days=1)
            thedate += delta
            self.optionValues[4] = str(startingep + epcount)
#            self.optionValues[5] = thedate.strftime(xbmc.getRegion("dateshort"))
            self.optionValues[5] = thedate.strftime("%d/%m/%Y")
            self.log("Past the scheduled date and time, skipping")
            self.saveOptions(channeldata)
            return True

        if chan > channelList.maxChannels or chan < 1 or epcount < 1:
            self.log("channel number is invalid")
            return False

        if len(channelList.channels) < chan or channelList.channels[chan - 1].isSetup == False:
            if channelList.myOverlay.isMaster:
                channelList.setupChannel(chan, True, True, False)
            else:
                channelList.setupChannel(chan, True, False, False)

        if channelList.channels[chan - 1].Playlist.size() < 1:
            self.log("scheduled channel isn't valid")
            return False

        # If the total time played value hasn't been updated
        if appending == False:
            timedif = self.nextScheduledTime - channelList.lastExitTime
        else:
            # If the total time played value HAS been updated
            timedif = self.nextScheduledTime + channeldata.totalTimePlayed - channelList.myOverlay.timeStarted

        showindex = 0

        # Find the proper location to insert the show(s)
        while timedif > 120 or showindex < self.startIndex:
            timedif -= channeldata.getItemDuration(showindex)
            showindex = channeldata.fixPlaylistIndex(showindex + 1)

            # Shows that there was a looparound, so exit.
            if showindex == 0:
                self.log("Couldn't find a location for the show")
                return False

        # If there is nothing after the selected show index and the time is still
        # too far away, don't do anything
        if (channeldata.Playlist.size() - (showindex + 1) <= 0) and (timedif < -300):
            return False

        # rearrange episodes to get an optimal time
        if timedif < -300 and channeldata.isRandom:
            # This is a crappy way to do it, but implementing a subset sum algorithm is
            # a bit daunting at the moment.  Plus this uses a minimum amount of memory, so as
            # a background task it works well.
            lasttime = int(abs(timedif))

            # Try a maximum of 5 loops
            for loops in range(5):
                newtime = self.rearrangeShows(showindex, lasttime, channeldata, channelList)

                if channelList.threadPause() == False:
                    return False

                # If no match found, then stop
                # If the time difference is less than 2 minutes, also stop
                if newtime == lasttime or newtime < 120:
                    break

                lasttime = newtime

        for i in range(epcount):
            item = PlaylistItem()
            item.duration = channelList.channels[chan - 1].getItemDuration(startingep + i)
            item.filename = channelList.channels[chan - 1].getItemFilename(startingep + i)
            item.description = channelList.channels[chan - 1].getItemDescription(startingep + i)
            item.title = channelList.channels[chan - 1].getItemTitle(startingep + i)
            item.episodetitle = channelList.channels[chan - 1].getItemEpisodeTitle(startingep + i)
            channeldata.Playlist.itemlist.insert(showindex, item)
            channeldata.Playlist.totalDuration += item.duration
            showindex += 1

        thedate = datetime.datetime.fromtimestamp(self.nextScheduledTime)
        delta = datetime.timedelta(days=1)
        thedate += delta
        self.startIndex = showindex
        self.optionValues[4] = str(startingep + epcount + 1)
#        self.optionValues[5] = thedate.strftime(xbmc.getRegion("dateshort"))
        self.optionValues[5] = thedate.strftime("%d/%m/%Y")
        self.saveOptions(channeldata)
        self.log("successfully scheduled at index " + str(self.startIndex))
        return True
예제 #2
0
    def addScheduledShow(self, channelList, channeldata, appending):
        self.log("addScheduledShow")
        chan = 0
        epcount = 0
        startingep = 0
        curchan = channeldata.channelNumber
        curruleid = self.getRuleIndex(channeldata)
        currentchantime = channelList.lastExitTime + channeldata.totalTimePlayed

        if channeldata.Playlist.size() == 0:
            return False

        try:
            chan = int(self.optionValues[0])
            epcount = int(self.optionValues[3])
            startingep = int(self.optionValues[4]) - 1
        except:
            pass

        if startingep < 0:
            startingep = 0

        # If the next scheduled show has already passed, then skip it
        if currentchantime > self.nextScheduledTime:
            thedate = datetime.datetime.fromtimestamp(self.nextScheduledTime)
            delta = datetime.timedelta(days=1)
            thedate += delta
            self.optionValues[4] = str(startingep + epcount)
            self.optionValues[5] = thedate.strftime("%d/%m/%Y")
            self.log("Past the scheduled date and time, skipping")
            self.saveOptions(channeldata)
            return True

        if chan > channelList.maxChannels or chan < 1 or epcount < 1:
            self.log("channel number is invalid")
            return False

        if len(channelList.channels) < chan or channelList.channels[
                chan - 1].isSetup == False:
            if channelList.myOverlay.isMaster:
                channelList.setupChannel(chan, True, True, False)
            else:
                channelList.setupChannel(chan, True, False, False)

        if channelList.channels[chan - 1].Playlist.size() < 1:
            self.log("scheduled channel isn't valid")
            return False

        # If the total time played value hasn't been updated
        if appending == False:
            timedif = self.nextScheduledTime - channelList.lastExitTime
        else:
            # If the total time played value HAS been updated
            timedif = self.nextScheduledTime + channeldata.totalTimePlayed - channelList.myOverlay.timeStarted

        showindex = 0

        # Find the proper location to insert the show(s)
        while timedif > 120 or showindex < self.startIndex:
            timedif -= channeldata.getItemDuration(showindex)
            showindex = channeldata.fixPlaylistIndex(showindex + 1)

            # Shows that there was a looparound, so exit.
            if showindex == 0:
                self.log("Couldn't find a location for the show")
                return False

        # If there is nothing after the selected show index and the time is still
        # too far away, don't do anything
        if (channeldata.Playlist.size() -
            (showindex + 1) <= 0) and (timedif < -300):
            return False

        # rearrange episodes to get an optimal time
        if timedif < -300 and channeldata.isRandom:
            # This is a crappy way to do it, but implementing a subset sum algorithm is
            # a bit daunting at the moment.  Plus this uses a minimum amount of memory, so as
            # a background task it works well.
            lasttime = int(abs(timedif))

            # Try a maximum of 5 loops
            for loops in range(5):
                newtime = self.rearrangeShows(showindex, lasttime, channeldata,
                                              channelList)

                if channelList.threadPause() == False:
                    return False

                # If no match found, then stop
                # If the time difference is less than 2 minutes, also stop
                if newtime == lasttime or newtime < 120:
                    break

                lasttime = newtime

        for i in range(epcount):
            item = PlaylistItem()
            item.duration = channelList.channels[chan - 1].getItemDuration(
                startingep + i)
            item.filename = channelList.channels[chan - 1].getItemFilename(
                startingep + i)
            item.description = channelList.channels[
                chan - 1].getItemDescription(startingep + i)
            item.title = channelList.channels[chan -
                                              1].getItemTitle(startingep + i)
            item.episodetitle = channelList.channels[
                chan - 1].getItemEpisodeTitle(startingep + i)
            channeldata.Playlist.itemlist.insert(showindex, item)
            channeldata.Playlist.totalDuration += item.duration
            showindex += 1

        thedate = datetime.datetime.fromtimestamp(self.nextScheduledTime)
        delta = datetime.timedelta(days=1)
        thedate += delta
        self.startIndex = showindex
        self.optionValues[4] = str(startingep + epcount + 1)
        self.optionValues[5] = thedate.strftime("%d/%m/%Y")
        self.saveOptions(channeldata)
        self.log("successfully scheduled at index " + str(self.startIndex))
        return True