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)
def test_video_unavailable(): try: raise exceptions.VideoUnavailable(video_id="YLnZklYFe7E") except exceptions.VideoUnavailable as e: assert e.video_id == "YLnZklYFe7E" # noqa: PT017 assert str(e) == "YLnZklYFe7E is unavailable"