示例#1
0
def test_recording_unavailable_error():
    # Ensure this can be caught as generic VideoUnavailable exception
    with pytest.raises(VideoUnavailable):
        raise RecordingUnavailable(video_id='5YceQ8YqYMc')
    try:
        raise RecordingUnavailable(video_id='5YceQ8YqYMc')
    except RecordingUnavailable as e:
        assert e.video_id == '5YceQ8YqYMc'  # noqa: PT017
        assert str(
            e) == '5YceQ8YqYMc does not have a live stream recording available'
示例#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)
示例#3
0
def test_recording_unavailable():
    try:
        raise RecordingUnavailable(video_id="5YceQ8YqYMc")
    except RecordingUnavailable as e:
        assert e.video_id == "5YceQ8YqYMc"  # noqa: PT017
        assert str(
            e) == "5YceQ8YqYMc does not have a live stream recording available"
    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)