Example #1
0
    def test_get_performance(self):
        videocache.init()
        videocache.clear()

        # Test data.
        # Randomly choose subset of videos.
        videos_sample = random.sample(VIDEOS, 5)

        # Test not cached time.
        for video in videos_sample:
            t0 = timeit.default_timer()
            video_path = videocache.get(video)
            t1 = timeit.default_timer()
            self.assertVideoReady(video_path)
            self.assertOkNotCachedGetTime(t0, t1)

            # Offset downloads.
            time.sleep(2)

        # Test cached time.
        for video in videos_sample:
            t0 = timeit.default_timer()
            video_path = videocache.get(video)
            t1 = timeit.default_timer()
            self.assertVideoReady(video_path)
            self.assertOkCachedGetTime(t0, t1)

            # Offset downloads.
            time.sleep(2)
def play(video, offset, duration, volume, speed):
    """
    :type video: youtube.Video
    :type offset: int
    :type duration: int
    :type volume: int
    :type speed: Speed
    """

    logger.info("play(video=%s, offset=%s, duration=%s, volume=%s, speed=%s)",video,offset,duration,volume, speed)

    # Inialise videocache.
    videocache.init()

    # Enforce minimum duration to make sure have time for OMXPlayer to start up
    # and begin playing.
    if duration < MIN_DURATION:
        duration = MIN_DURATION
        logger.info("Enforcing minimum duration of %s seconds" % MIN_DURATION)

    if pyomxplayer.is_omxplayer_available():
        video_path = videocache.get(video)
        logger.info("OMXPlayer(%s)" % video_path)
        p = pyomxplayer.OMXPlayer(video_path)
        # Delaying changes to give OMXPlayer time to set up and be ready to accept input
        time.sleep(OMXPLAYER_START_UP)
        p.seek(offset)
        p.set_volume(volume)
        p.set_speed(speed)
        time.sleep(duration-OMXPLAYER_START_UP)
        p.stop()
    else:
        logger.info("OMXPlayer not available, calling `time.sleep`.")
        time.sleep(duration)
def play(video, offset, duration, volume, speed):
    """
    :type video: youtube.Video
    :type offset: int
    :type duration: int
    :type volume: int
    :type speed: Speed
    """

    logger.info("play(video=%s, offset=%s, duration=%s, volume=%s, speed=%s)",
                video, offset, duration, volume, speed)

    # Inialise videocache.
    videocache.init()

    # Enforce minimum duration to make sure have time for OMXPlayer to start up
    # and begin playing.
    if duration < MIN_DURATION:
        duration = MIN_DURATION
        logger.info("Enforcing minimum duration of %s seconds" % MIN_DURATION)

    if pyomxplayer.is_omxplayer_available():
        video_path = videocache.get(video)
        logger.info("OMXPlayer(%s)" % video_path)
        p = pyomxplayer.OMXPlayer(video_path)
        # Delaying changes to give OMXPlayer time to set up and be ready to accept input
        time.sleep(OMXPLAYER_START_UP)
        p.seek(offset)
        p.set_volume(volume)
        p.set_speed(speed)
        time.sleep(duration - OMXPLAYER_START_UP)
        p.stop()
    else:
        logger.info("OMXPlayer not available, calling `time.sleep`.")
        time.sleep(duration)