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

Code before:

        for mobj in re.finditer(r'<a[^>]+href="(?P<video_url>[^"]+download=true[^"]+)".*>(?P<ext>[^\s]+) (?P<quality>[^<]+)p</a>', webpage):
            url, ext, quality = mobj.groups()
            formats.append({
                'url': url,
                'ext': ext.lower(),
                'quality': quality,
            })

        categories = None
        creator = None
        uploader, uploader_url = None, None
        for col in get_elements_by_class('col', webpage):
            label = clean_html(get_element_by_class('label', col))
            if label == 'Categories:':
                categories = list(map(clean_html, get_elements_by_class('item', col)))
            elif label == 'Artist:':
                creator = join_nonempty(*map(clean_html, get_elements_by_class('item', col)), delim=', ')
            elif label == 'Uploaded By:':
                uploader = clean_html(get_element_by_class('name', col))
                uploader_url = extract_attributes(get_element_html_by_class('name', col) or '').get('href')

        json_ld = self._search_json_ld(webpage, video_id, default={})

        return {
            **traverse_obj(json_ld, ({
                'title': 'title',
                'view_count': 'view_count',
                'like_count': 'like_count',
                'duration': 'duration',
                'timestamp': 'timestamp',
                'description': 'description',
                'thumbnail': ('thumbnails', 0, 'url'),
            })),
            'id': video_id,
            'formats': formats,
            'title': self._html_extract_title(webpage),
            'thumbnail': self._html_search_regex(
                r'preview_url:\s+\'([^\']+)\'', webpage, 'thumbnail', default=None),
            'duration': parse_duration(self._html_search_regex(
                r'"icon-clock"></i>\s+<span>((?:\d+:?)+)', webpage, 'duration', default=None)),
            'view_count': int_or_none(self._html_search_regex(
                r'"icon-eye"></i>\s+<span>([ \d]+)', webpage, 'views', default='').replace(' ', '')),
            'like_count': str_to_int(remove_end(
                get_element_by_class('voters count', webpage), ' likes')),
            'comment_count': int_or_none(self._search_regex(
                r'[^(]+\((\d+)\)', get_element_by_attribute('href', '#tab_comments', webpage), 'comment count', fatal=False)),
            'age_limit': 18,
            'creator': creator,
            'uploader': uploader,
            'uploader_url': uploader_url,

Review comment (suggestion):
```suggestion
        return {
            **traverse_obj(self._search_json_ld(webpage, video_id, default={}), ({
```

Code after:
        for mobj in re.finditer(r'<a[^>]+href="(?P<video_url>[^"]+download=true[^"]+)".*>(?P<ext>[^\s]+) (?P<quality>[^<]+)p</a>', webpage):
            url, ext, quality = mobj.groups()
            formats.append({
                'url': url,
                'ext': ext.lower(),
                'quality': quality,
            })

        categories, creator, uploader, uploader_url = [None] * 4
        for col in get_elements_by_class('col', webpage):
            label = clean_html(get_element_by_class('label', col))
            if label == 'Categories:':
                categories = list(map(clean_html, get_elements_by_class('item', col)))
            elif label == 'Artist:':
                creator = join_nonempty(*map(clean_html, get_elements_by_class('item', col)), delim=', ')
            elif label == 'Uploaded By:':
                uploader = clean_html(get_element_by_class('name', col))
                uploader_url = extract_attributes(get_element_html_by_class('name', col) or '').get('href')

        return {
            **traverse_obj(self._search_json_ld(webpage, video_id, default={}), ({
                'title': 'title',
                'view_count': 'view_count',
                'like_count': 'like_count',
                'duration': 'duration',
                'timestamp': 'timestamp',
                'description': 'description',
                'thumbnail': ('thumbnails', 0, 'url'),
            })),
            'id': video_id,
            'formats': formats,
            'title': self._html_extract_title(webpage),
            'thumbnail': self._html_search_regex(
                r'preview_url:\s+\'([^\']+)\'', webpage, 'thumbnail', default=None),
            'duration': parse_duration(self._html_search_regex(
                r'"icon-clock"></i>\s+<span>((?:\d+:?)+)', webpage, 'duration', default=None)),
            'view_count': int_or_none(self._html_search_regex(
                r'"icon-eye"></i>\s+<span>([ \d]+)', webpage, 'views', default='').replace(' ', '')),
            'like_count': parse_count(get_element_by_class('voters count', webpage)),
            'comment_count': int_or_none(self._search_regex(
                r'[^(]+\((\d+)\)', get_element_by_attribute('href', '#tab_comments', webpage), 'comment count', fatal=False)),
            'age_limit': 18,
            'creator': creator,
            'uploader': uploader,
            'uploader_url': uploader_url,
            'categories': categories,
            'tags': list(map(unescapeHTML, re.findall(
                r'<a class="tag_item"[^>]+\bhref="https://rule34video\.com/tags/\d+/"[^>]*>(?P<tag>[^>]*)</a>', webpage))),
        }