Exemplo n.º 1
0
def test_region_locked_error():
    # Ensure this can be caught as generic VideoUnavailable exception
    with pytest.raises(exceptions.VideoUnavailable):
        raise exceptions.VideoRegionBlocked('hZpzr8TbF08')
    try:
        raise exceptions.VideoRegionBlocked('hZpzr8TbF08')
    except exceptions.VideoRegionBlocked as e:
        assert e.video_id == 'hZpzr8TbF08'  # noqa: PT017
        assert str(e) == 'hZpzr8TbF08 is not available in your region'
Exemplo n.º 2
0
    def check_availability(self):
        """Check whether the video is available.

        Raises different exceptions based on why the video is unavailable,
        otherwise does nothing.
        """
        status, messages = extract.playability_status(self.watch_html)

        for reason in messages:
            if status == 'UNPLAYABLE':
                if reason == (
                        'Join this channel to get access to members-only content '
                        'like this video, and other exclusive perks.'):
                    raise exceptions.MembersOnly(video_id=self.video_id)
                elif reason == 'This live stream recording is not available.':
                    raise exceptions.RecordingUnavailable(
                        video_id=self.video_id)
                else:
                    if reason == 'Video unavailable':
                        if extract.is_region_blocked(self.watch_html):
                            raise exceptions.VideoRegionBlocked(
                                video_id=self.video_id)
                    raise exceptions.VideoUnavailable(video_id=self.video_id)
            elif status == 'LOGIN_REQUIRED':
                if reason == ('This is a private video. '
                              'Please sign in to verify that you may see it.'):
                    raise exceptions.VideoPrivate(video_id=self.video_id)
            elif status == 'ERROR':
                if reason == 'Video unavailable':
                    raise exceptions.VideoUnavailable(video_id=self.video_id)
            elif status == 'LIVE_STREAM':
                raise exceptions.LiveStreamError(video_id=self.video_id)