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

Code before:
            stream + '?' + cdn, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', headers=geo_headers)

        return {
            'http_headers': headers,
            'id': video_id,
            'title': title,
            'formats': formats,
            'thumbnail': content.get('dataPoster') or traverse_obj(config, 'poster', 'imageUrl'),
            'duration': traverse_obj(content, ('dataDuration', {int_or_none})),
        }

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        article = self._parse_json(self._search_regex(
            r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})',
            webpage, 'article'), display_id)['article']
        title = article.get('title')
        description = clean_html(article.get('leadParagraph')) or ''
        if article.get('editorialType') != 'VID':
            entries = []
            body = [article.get('opening')]
            body.extend(traverse_obj(article, ('body', {list})))
            for p in body:
                if not isinstance(p, dict):
                    continue
                content = p.get('content')
                if not content:
                    continue
                type_ = p.get('type')
                if type_ == 'paragraph':
                    content_str = str_or_none(content)
                    if content_str:
                        description += content_str
                    continue
                if type_ == 'video' and isinstance(content, dict):
                    entries.append(self._parse_content(content, url))
            return self.playlist_result(
                entries, str_or_none(article.get('id')), title, description)
        content = article['opening']['content']
        info = self._parse_content(content, url)
        info['description'] = description
        return info


Review comment (refactor):
`{list}` will not guarantee a list; it will return `None` if `'body'` is not a list. We can use branching (`...`) to guarantee a list result, and then expect `{dict}` to filter non-dict results out of the returned list:
```py
            body.extend(traverse_obj(article, ('body', ..., {dict})))
            for p in traverse_obj(article, ((('opening', all), 'body'), lambda _, v: v['content'])):
```

but I think it'd be better to add the line above this in this traversal and simplify some of the code below this with filtering:

```suggestion
            for p in traverse_obj(article, ((('opening', all), 'body'), lambda _, v: v['content'])):
```

Code after:
            'duration': 50,
            'thumbnail': 'https://album.mediaset.es/eimg/2017/11/02/1tlQLO5Q3mtKT24f3EaC24.jpg',
        },
    }, {
        # video in opening's content
        'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html',
        'info_dict': {
            'id': '1691427',
            'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
            'description': r're:Fiorella, la sobrina de Edmundo Arrocet, concedió .{727}',
        },
        'playlist': [{
            'md5': 'adb28c37238b675dad0f042292f209a7',
            'info_dict': {
                'id': 'TpI2EttSDAReWpJ1o0NVh2',
                'ext': 'mp4',
                'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"',
                'duration': 1015,
                'thumbnail': 'https://album.mediaset.es/eimg/2020/02/29/5opaC37lUhKlZ7FoDhiVC.jpg',
            },
        }],
        'params': {
            'skip_download': True,
        },
    }, {
        'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html',
        'only_matching': True,
    }, {
        'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html',
        'only_matching': True,
    }, {
        'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        article = self._search_json(
            r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=',
            webpage, 'article', display_id)['article']
        description = traverse_obj(article, ('leadParagraph', {clean_html}, filter))

        if article.get('editorialType') != 'VID':
            entries = []

            for p in traverse_obj(article, ((('opening', all), 'body'), lambda _, v: v['content'])):
                content = p['content']
                type_ = p.get('type')
                if type_ == 'paragraph' and isinstance(content, str):
                    description = join_nonempty(description, content, delim='')