def test_private_error(): # Ensure this can be caught as generic VideoUnavailable exception with pytest.raises(exceptions.VideoUnavailable): raise exceptions.VideoPrivate('m8uHb5jIGN8') try: raise exceptions.VideoPrivate('m8uHb5jIGN8') except exceptions.VideoPrivate as e: assert e.video_id == 'm8uHb5jIGN8' # noqa: PT017 assert str(e) == 'm8uHb5jIGN8 is a private video'
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)