Example #1
0
def test_private_error():
    # Ensure this can be caught as generic VideoUnavailable exception
    with pytest.raises(VideoUnavailable):
        raise VideoPrivate('m8uHb5jIGN8')
    try:
        raise VideoPrivate('m8uHb5jIGN8')
    except VideoPrivate as e:
        assert e.video_id == 'm8uHb5jIGN8'  # noqa: PT017
        assert str(e) == 'm8uHb5jIGN8 is a private video'
Example #2
0
    def prefetch(self) -> None:
        """Eagerly download all necessary data.

        Eagerly executes all necessary network requests so all other
        operations don't does need to make calls outside of the interpreter
        which blocks for long periods of time.

        :rtype: None
        """
        self.watch_html = request.get(url=self.watch_url)
        if self.watch_html is None:
            raise VideoUnavailable(video_id=self.video_id)
        self.age_restricted = extract.is_age_restricted(self.watch_html)

        if extract.is_private(self.watch_html):
            raise VideoPrivate(video_id=self.video_id)

        if not extract.recording_available(self.watch_html):
            raise RecordingUnavailable(video_id=self.video_id)

        if self.age_restricted:
            if not self.embed_html:
                self.embed_html = request.get(url=self.embed_url)
            self.vid_info_url = extract.video_info_url_age_restricted(
                self.video_id, self.watch_url
            )
        else:
            self.vid_info_url = extract.video_info_url(
                video_id=self.video_id, watch_url=self.watch_url
            )

        self.vid_info_raw = request.get(self.vid_info_url)
        if not self.age_restricted:
            self.js_url = extract.js_url(self.watch_html)
            self.js = request.get(self.js_url)
    def check_availability(self):
        """Check whether the video is available.
        Raises different exceptions based on why the video is unavailable,
        otherwise does nothing.

        """
        if self.watch_html is None:
            raise VideoUnavailable(video_id=self.video_id)

        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 MembersOnly(video_id=self.video_id)
                elif reason == 'This live stream recording is not available.':
                    raise RecordingUnavailable(video_id=self.video_id)
                else:
                    if reason == 'Video unavailable':
                        if extract.is_region_blocked(self.watch_html):
                            raise VideoRegionBlocked(video_id=self.video_id)
                    raise 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 VideoPrivate(video_id=self.video_id)
            elif status == 'ERROR':
                if reason == 'Video unavailable':
                    raise VideoUnavailable(video_id=self.video_id)
Example #4
0
def test_private_error():
    try:
        raise VideoPrivate('m8uHb5jIGN8')
    except VideoPrivate as e:
        assert e.video_id == 'm8uHb5jIGN8'  # noqa: PT017
        assert str(e) == 'm8uHb5jIGN8 is a private video'
Example #5
0
def test_private_error():
    try:
        raise VideoPrivate('mRe-514tGMg')
    except VideoPrivate as e:
        assert e.video_id == 'mRe-514tGMg'  # noqa: PT017
        assert str(e) == 'mRe-514tGMg is a private video'