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

Code before:
            'age_limit': 18,
            'duration': parse_duration(public_data.get('runtime')),
            'cast': cast,
            'tags': traverse_obj(public_data, ('niches', ..., 'niche'), default=[]),
            'thumbnail': str_or_none(public_data.get('player_poster')),
            'subtitles': subtitles,
        }

        is_free_scene = traverse_obj(public_data, ('price', 'is_available_for_free'), default=False, expected_type=bool)
        if is_free_scene:
            metadata['availability'] = 'needs_auth'
        else:
            metadata['availability'] = 'premium_only'

        if (not public_data.get('is_purchased')) or (not is_free_scene):
            self.raise_login_required('You are either not logged in or do not have access to this scene',
                                      metadata_available=True, method='cookies')
            return metadata

        media_id = traverse_obj(public_data, ('medias', lambda _, v: v['title'] == 'Full video', 'media_id'),
                                default=[], expected_type=int)
        if not media_id:
            self.raise_no_formats(msg='Could not find stream id', video_id=video_id)

        # traverse_obj branches, therefore media_id is a list
        media_id = media_id[0]

        headers = {
            'Accept': '*/*',
            'Accept-Language': 'en-US;q=0.7,en;q=0.3',
            'Accept-Encoding': 'gzip, deflate, br',
            'X-Requested-With': 'XMLHttpRequest',
            'DNT': '1',
            'Connection': 'keep-alive',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin'
        }
        stream_data = self._download_json(f'https://pornbox.com/media/{media_id}/stream', video_id=video_id,
                                          headers=headers, note='Getting manifest urls')

        get_quality = qualities(['web', 'vga', 'hd', '1080p', '4k', '8k'])
        formats = []
        for q in stream_data.get('qualities') or []:
            formats.append({
                'url': q.get('src'),
                'vbr': int_or_none(q.get('bitrate'), scale=1000),
                'format_id': str_or_none(q.get('quality')),
                'quality': get_quality(q.get('quality')),
                'width': int_or_none(str_or_none(q.get('size'), default='')[:-1])
            })

Review comment (suggestion):
```suggestion
        media_id = traverse_obj(public_data, (
            'medias', lambda _, v: v['title'] == 'Full video', 'media_id', {int}), get_all=False)
        if not media_id:
            self.raise_no_formats('Could not find stream id', video_id=video_id)
```

Code after:
            }),
            'age_limit': 18,
            'timestamp': parse_iso8601(traverse_obj(
                public_data, ('studios', 'release_date'), 'publish_date')),
            'availability': self._availability(needs_auth=True, needs_premium=not is_free_scene),
            'subtitles': subtitles,
        }

        if not public_data.get('is_purchased') or not is_free_scene:
            self.raise_login_required(
                'You are either not logged in or do not have access to this scene', metadata_available=True)
            return metadata

        media_id = traverse_obj(public_data, (
            'medias', lambda _, v: v['title'] == 'Full video', 'media_id', {int}), get_all=False)
        if not media_id:
            self.raise_no_formats('Could not find stream id', video_id=video_id)

        stream_data = self._download_json(
            f'https://pornbox.com/media/{media_id}/stream', video_id=video_id, note='Getting manifest urls')

        get_quality = qualities(['web', 'vga', 'hd', '1080p', '4k', '8k'])
        metadata['formats'] = traverse_obj(stream_data, ('qualities', lambda _, v: v['src'], {
            'url': 'src',
            'vbr': ('bitrate', {functools.partial(int_or_none, scale=1000)}),
            'format_id': ('quality', {str_or_none}),
            'quality': ('quality', {get_quality}),
            'width': ('size', {lambda x: int(x[:-1])}),
        }))

        return metadata