Example #1
0
 def test_hasCommercials_True(self):
     p = RecordedProgram(pdata({'programflags':FlagMask.FL_COMMFLAG | FlagMask.FL_AUTOEXP}), **self.pkwargs)
     commBreaks = []
     commBreaks.append(CommercialBreak(120,180))
     when(self.conn).getCommercialBreaks(p).thenReturn(commBreaks)
     log.debug('comms = %s' % len(p.getCommercials()))
     self.assertTrue(p.hasCommercials())    
Example #2
0
    def test_PlayerSkippingAroundWhenEntersCommBreakDoesntSkipCommercial(self):
        # Setup
        when(self.player).isPlaying().thenReturn(True)
        when(self.program).getCommercials().thenReturn(
            [CommercialBreak(500, 600)])

        # close to beginning = within 2 secs from start of commercial
        when(self.player).getTime().thenReturn(501).thenReturn(502).thenReturn(
            504).thenReturn(505)

        # mock a valid tracker history
        trackerHistory = []
        for x in range(499, 500):
            trackerHistory.append(TrackerSample(time.time() + (x - 499), x))
        when(self.tracker).getHistory(any()).thenReturn(trackerHistory)

        # Test
        skipper = TrackingCommercialSkipper(self.player, self.program,
                                            self.translator)
        skipper.onPlayBackStarted()
        time.sleep(1)
        when(self.player).isPlaying().thenReturn(False)
        skipper.onPlayBackStopped()

        # Verify
        verify(self.player, times(0)).seekTime(any())
Example #3
0
    def test_PlayerNeverEntersAnyCommBreaks(self):
        # Setup
        when(self.player).isPlaying().thenReturn(True)
        when(self.program).getCommercials().thenReturn(
            [CommercialBreak(100, 200),
             CommercialBreak(600, 700)])
        when(self.player).getTime().thenReturn(500)

        # Test
        skipper = TrackingCommercialSkipper(self.player, self.program,
                                            self.translator)
        skipper.onPlayBackStarted()
        time.sleep(2)
        when(self.player).isPlaying().thenReturn(False)
        skipper.onPlayBackStopped()

        # Verify
        verify(self.player, times(0)).seekTime(any())
Example #4
0
 def test_getCommercials_ReturnsOneCommercial(self):
     p = RecordedProgram(pdata({'programflags':FlagMask.FL_COMMFLAG | FlagMask.FL_AUTOEXP}), **self.pkwargs)
     commBreaks = []
     commBreaks.append(CommercialBreak(120,180))
     when(self.conn).getCommercialBreaks(p).thenReturn(commBreaks)
     result = p.getCommercials()    
     log.debug('commercials = %s'%result)
     self.assertEqual(commBreaks, result)
     verify(self.conn).getCommercialBreaks(p)
Example #5
0
    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
Example #6
0
 def test_isDuring_AfterCommercialReturnsFalse(self):
     commercial = CommercialBreak(100, 200)
     self.assertFalse(commercial.isDuring(350))
Example #7
0
 def test_isDuring_True(self):
     commercial = CommercialBreak(100, 200)
     self.assertTrue(commercial.isDuring(150))
Example #8
0
 def test_isDuring_AfterCommercialReturnsFalse(self):
     commercial = CommercialBreak(100, 200)
     self.assertFalse(commercial.isDuring(350))
Example #9
0
 def test_isDuring_True(self):
     commercial = CommercialBreak(100, 200)
     self.assertTrue(commercial.isDuring(150))
Example #10
0
 def test_constructor_StartAfterEndFailsAssertion(self):
     try:
         CommercialBreak(200, 100)
     except AssertionError, ae:
         log.debug('Error = %s' % ae)
Example #11
0
 def test_constructor(self):
     commercial = CommercialBreak(100, 200)
     self.assertTrue(commercial is not None)