Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/nest.py (Python)

Code before:
        'only_matching': True,
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.pacificblue.biz/noyo-harbor-webcam/',
        'info_dict': {
            'id': '4fvYdSo8AX',
            'ext': 'mp4',
            'title': 'startswith:Outside ',
            'alt_title': 'Outside',
            'description': '<null>',
            'location': 'Los Angeles',
            'availability': 'public',
            'thumbnail': r're:https?://',
            'live_status': 'is_live',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        data = self._download_json(
            f'https://video.nest.com/api/dropcam/cameras.get_by_public_token?token={video_id}', video_id)
        item = traverse_obj(data, ('items', 0, {dict}))
        uuid = item.get('uuid')
        stream_domain = item.get('live_stream_host')
        if not stream_domain or not uuid:
            raise ExtractorError('Unable to construct playlist URL')

        thumb_domain = item.get('nexus_api_nest_domain_host')
        return {
            'id': video_id,
            **traverse_obj(item, {
                'description': ('description', {str}),
                'title': (('title', 'name', 'where'), {str}, filter, any),
                'alt_title': ('name', {str}),
                'location': ((('timezone', {lambda x: x.split('/')[1].replace('_', ' ')}), 'where'), {str}, filter, any),
            }),
            'thumbnail': f'https://{thumb_domain}/get_image?uuid={uuid}&public={video_id}' if thumb_domain else None,
            'availability': 'public' if item.get('is_public') else None,
            'formats': self._extract_m3u8_formats(
                f'https://{stream_domain}/nexus_aac/{uuid}/playlist.m3u8?public={video_id}', video_id, 'mp4', live=True),
            'is_live': True,
        }


class NestClipIE(InfoExtractor):
    _VALID_URL = r'https?://video\.nest\.com/(?:embedded/)?clip/(?P<id>\w+)'
    _EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})']

Review comment (suggestion):
it's fatal in the very next line if `data['items'][0]` isn't a dict, and we don't use any other part of `data`, so we might as well do this above:

```py
       item = self._download_json(
            'https://video.nest.com/api/dropcam/cameras.get_by_public_token',
            video_id, query={'token': video_id})['items'][0]
```

```suggestion
```

Code after:
        'only_matching': True,
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.pacificblue.biz/noyo-harbor-webcam/',
        'info_dict': {
            'id': '4fvYdSo8AX',
            'ext': 'mp4',
            'title': 'startswith:Outside ',
            'alt_title': 'Outside',
            'description': '<null>',
            'location': 'Los Angeles',
            'availability': 'public',
            'thumbnail': r're:https?://',
            'live_status': 'is_live',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        item = self._download_json(
            'https://video.nest.com/api/dropcam/cameras.get_by_public_token',
            video_id, query={'token': video_id})['items'][0]
        uuid = item.get('uuid')
        stream_domain = item.get('live_stream_host')
        if not stream_domain or not uuid:
            raise ExtractorError('Unable to construct playlist URL')

        thumb_domain = item.get('nexus_api_nest_domain_host')
        return {
            'id': video_id,
            **traverse_obj(item, {
                'description': ('description', {str}),
                'title': (('title', 'name', 'where'), {str}, filter, any),
                'alt_title': ('name', {str}),
                'location': ((('timezone', {lambda x: x.split('/')[1].replace('_', ' ')}), 'where'), {str}, filter, any),
            }),
            'thumbnail': update_url_query(
                f'https://{thumb_domain}/get_image',
                {'uuid': uuid, 'public': video_id}) if thumb_domain else None,
            'availability': self._availability(is_private=item.get('is_public') is False),
            'formats': self._extract_m3u8_formats(
                f'https://{stream_domain}/nexus_aac/{uuid}/playlist.m3u8',
                video_id, 'mp4', live=True, query={'public': video_id}),
            'is_live': True,
        }