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

Code before:

    _TESTS = [{
        'url': 'https://2m.ma/fr/news/Kan-Ya-Mkan-d%C3%A9poussi%C3%A8re-l-histoire-du-phare-du-Cap-Beddouza-20221028',
        'md5': 'f434e2552b1bd1004fc04737b59c03a9',
        'info_dict': {
            'id': '635c5d1233b83834e35b282e',
            'ext': 'mp4',
            'title': 'Kan Ya Mkan d\u00e9poussi\u00e8re l\u2019histoire du phare du Cap Beddouza',
            'description': 'md5:99dcf29b82f1d7f2a4acafed1d487527',
            'thumbnail': 'https://2msoread-ww.amagi.tv/mediasfiles/videos/images/2022/10/27/1666869608ba-kane-ya-mkane-27-10-2022.png'
        }
    }, {
        'url': 'https://2m.ma/fr/news/Interview-Casablanca-hors-des-sentiers-battus-avec-Abderrahim-KASSOU-Replay--20221017',
        'md5': '7aca29f02230945ef635eb8290283c0c',
        'info_dict': {
            'id': '634d9e108b70d40bc51a844b',
            'ext': 'mp4',
            'title': 'Interview: Casablanca hors des sentiers battus avec Abderrahim KASSOU (Replay) ',
            'description': 'md5:3b8e78111de9fcc6ef7f7dd6cff2430c',
            'thumbnail': 'https://2msoread-ww.amagi.tv/mediasfiles/videos/images/2022/10/17/1666031205e8b5613cf7fd24cc10a116844b23bfd4.png'
        }
    }]

    def _real_extract(self, url):
        lang = self._search_regex(self._VALID_URL, url, 'lang')
        article_name = self._match_id(url)
        video = self._download_json(
            f'https://2m.ma/api/articlesByUrl?lang={lang}&url=/news/{article_name}', article_name)['response']['article'][0]
        return {
            'id': video.get('id'),
            'title': video.get('title'),
            'url': video['image'][0],
            'description': video.get('content'),
            'thumbnail': url_or_none(video.get('cover')),
        }


Review comment (suggestion):
```suggestion
        article_name, lang = self._match_valid_url(url).group('id', 'lang')
```

Code after:

    _TESTS = [{
        'url': 'https://2m.ma/fr/news/Kan-Ya-Mkan-d%C3%A9poussi%C3%A8re-l-histoire-du-phare-du-Cap-Beddouza-20221028',
        'md5': '43d5e693a53fa0b71e8a5204c7d4542a',
        'info_dict': {
            'id': '635c5d1233b83834e35b282e',
            'ext': 'mp4',
            'title': 'Kan Ya Mkan d\u00e9poussi\u00e8re l\u2019histoire du phare du Cap Beddouza',
            'description': 'md5:99dcf29b82f1d7f2a4acafed1d487527',
            'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
        }
    }, {
        'url': 'https://2m.ma/fr/news/Interview-Casablanca-hors-des-sentiers-battus-avec-Abderrahim-KASSOU-Replay--20221017',
        'md5': '7aca29f02230945ef635eb8290283c0c',
        'info_dict': {
            'id': '634d9e108b70d40bc51a844b',
            'ext': 'mp4',
            'title': 'Interview: Casablanca hors des sentiers battus avec Abderrahim KASSOU (Replay) ',
            'description': 'md5:3b8e78111de9fcc6ef7f7dd6cff2430c',
            'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$'
        }
    }]

    def _real_extract(self, url):
        article_name, lang = self._match_valid_url(url).group('id', 'lang')
        video = self._download_json(
            f'https://2m.ma/api/articlesByUrl?lang={lang}&url=/news/{article_name}', article_name)['response']['article'][0]
        return {
            'id': video['id'],
            'title': video.get('title'),
            'url': video['image'][0],
            'description': video.get('content'),
            'thumbnail': url_or_none(video.get('cover')),
        }