~registry/hyberia/0.4

« back to all changes in this revision

Viewing changes to hyberia/playlist.py

  • Committer: Mathieu Charron
  • Date: 2010-10-08 02:05:04 UTC
  • mfrom: (62.1.1 hyberia)
  • Revision ID: mathieu.charron@elwillow.net-20101008020504-or24q4r12d6cmbo2
Lastest fixed before C&K.
Fixing playlist and deamon.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
            self.logger.warning("This is a parsing error. Strings in json must be delimited with \" instead of ' .")
105
105
            self.logger.critical(e)
106
106
            raise PlayListImportErrorException()
107
 
 
 
107
        
108
108
        #Verify that some data exists
109
109
        for elem in ["blocks","resources"]:
110
110
            if not elem in playListStruct:
142
142
                        self.logger.critical("Block %s on %s does not have a %s!" %s (timeBlock,dateBlock,item))
143
143
                        raise PlayListImportErrorException()
144
144
 
145
 
 
146
145
                #blockid is date with seconds, move to unix timestamp
147
146
                blockId = ((int(dateBlock) * 10000) + int(timeBlock)) * 100
148
147
                blockId = datetime.datetime.strptime(str(blockId), "%Y%m%d%H%M%S")
174
173
 
175
174
    def getCurrentBlock(self):
176
175
        curTimeId = int(time.time())
177
 
        curBlock = None
178
 
 
 
176
        prevBlock = None
179
177
        for blockId in self._playList:
 
178
            ''' Loop through the blocks to find the one that should be playing
 
179
            or will play next
 
180
            
 
181
            if the blockId is greater than the curTimeId, it means we either
 
182
            have found the currently playing block or the one that will be played.
 
183
            '''
180
184
            if blockId < curTimeId:
181
 
                curBlock = blockId
 
185
                prevBlock = blockId
182
186
                continue
 
187
            else:
 
188
                '''If the previous block totalruntime is greater than the current time
 
189
                return it'''
 
190
                if ( self._blocks[prevBlock]['totalRunTime'] + prevBlock ) > curTimeId:
 
191
                    return self._blocks[prevBlock]
 
192
                else:
 
193
                    return self._blocks[blockId]
183
194
 
184
 
            if not curBlock:
185
 
                curBlock = blockId
186
 
            return self._blocks[curBlock]
 
195
        ''' We could fall here if we have reached the last playing block'''
 
196
        if prevBlock:
 
197
            if ( self._blocks[prevBlock]['totalRunTime'] + prevBlock ) > curTimeId:
 
198
                return self._blocks[prevBlock]      
187
199
        return None