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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_preload(self):

        import app.api.youtube
        from app.models import examples

        videocache.init()

        # Every video value that occurs in an example or the editor interface.
        seed_videos_urls = [
            examples.GANGNAM_STYLE,
            examples.SURPRISE,
            examples.FREEFALL,
            examples.PEP_TALK,
            examples.ROPE_SWING,
            examples.FIREWORKS,
            examples.MAC_ASKILL,
            examples.CAMBRIDGE_HARLEM
        ]
        seed_videos = map(Video.from_web_url, seed_videos_urls)

        # Derive set of videos likely to be returned by related to.
        related_videos = set()
        for seed_video in seed_videos:
            related_videos |= set(seed_video.related())

        videocache.prime(seed_videos)
        videocache.prime(related_videos)
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)
Ejemplo n.º 5
0
 def test_clear(self):
     videocache.init()
     videocache.clear()