def test_frames2seconds(self): s = frames2seconds(1000, 29.97) log.debug('1000 frames @ 29.97fps = %s seconds' % s) self.assertEqual(33.37, s) s = frames2seconds(0, 29.97) log.debug('0 frames @ 29.97fps = %s seconds' % s) self.assertEqual(0.0, s) s = frames2seconds(99999999L, 29.97) log.debug('99999999L frames @ 29.97fps = %s seconds' % s) self.assertEqual(3336669.97, s)
def getCommercialBreaks(self, program): """ @type program: RecordedProgram @return: List of commercial breaks for the given recording in chronological order @rtype: CommercialBreak[] """ COMM_START = 4 COMM_END = 5 commBreaks = [] command = 'QUERY_COMMBREAK %s %s' % (program.getChannelId(), program.starttimets()) reply = self._sendRequest(self.cmdSock, [command]) if len(reply) == 0: return commBreaks numRecs = int(reply.pop(0)) if numRecs in ( -1, 0, ): return commBreaks if numRecs % 2 != 0: raise ClientException, 'Expected an even number of comm break records but got %s instead' % numRecs fps = program.getFPS() for i in xrange(0, numRecs, 2): # skip by 2's - start/end come in pairs commFlagStart = int(reply.pop(0)) if commFlagStart != COMM_START: raise ProtocolException, 'Expected COMM_START for record %s but got %s instead' % ( (i + 1), commFlagStart) frameStart = self.protocol.readLong(reply, remove=True) commFlagEnd = int(reply.pop(0)) if commFlagEnd != COMM_END: raise ProtocolException, 'Expected COMM_END for record %s but got %s instead' % ( (i + 2), commFlagEnd) frameEnd = self.protocol.readLong(reply, remove=True) from mythbox.mythtv.domain import frames2seconds, CommercialBreak commBreaks.append( CommercialBreak(frames2seconds(frameStart, fps), frames2seconds(frameEnd, fps))) log.debug('%s commercials in %s' % (len(commBreaks), safe_str(program.title()))) return commBreaks
def getCommercialBreaks(self, program): """ @type program: RecordedProgram @return: List of commercial breaks for the given recording in chronological order @rtype: CommercialBreak[] """ COMM_START = 4 COMM_END = 5 commBreaks = [] command = 'QUERY_COMMBREAK %s %s' %(program.getChannelId(), program.starttimets()) reply = self._sendRequest(self.cmdSock, [command]) if len(reply) == 0: return commBreaks numRecs = int(reply[0]) if numRecs in (-1,0,): return commBreaks if numRecs % 2 != 0: raise ClientException, 'Expected an even number of comm break records but got %s instead' % numRecs fps = program.getFPS() recSize = 3 # marker, highByte, lowByte for i in xrange(0, numRecs, 2): # skip by 2's - start/end come in pairs baseIndex = i * recSize commFlagStart = int(reply[baseIndex + 1]) if commFlagStart != COMM_START: raise ProtocolException, 'Expected COMM_START for record %s but got %s instead' % ((i+1), commFlagStart) frameStart = decodeLongLong(reply[baseIndex + 3], reply[baseIndex + 2]) commFlagEnd = int(reply[baseIndex + 4]) if commFlagEnd != COMM_END: raise ProtocolException, 'Expected COMM_END for record %s but got %s instead' %((i+2), commFlagEnd) frameEnd = decodeLongLong(reply[baseIndex + 6], reply[baseIndex + 5]) from mythbox.mythtv.domain import frames2seconds, CommercialBreak commBreaks.append(CommercialBreak(frames2seconds(frameStart, fps), frames2seconds(frameEnd, fps))) log.debug('%s commercials in %s' %(len(commBreaks), safe_str(program.title()))) return commBreaks