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

Code before:

class MaarivIE(InfoExtractor):
    IE_NAME = 'maariv.co.il'
    _VALID_URL = r'(https?://)?(www\.)?(m\.)?maariv\.co\.il(?:/[^/]+)*/Article-(?P<id>\d{7})'
    _TESTS = [
        {
            'url': 'https://www.maariv.co.il/news/law/Article-1044008',
            'info_dict': {
                'id': '1044008',
                'title': '.*',
            },
        }
    ]

    @staticmethod
    def extract_resolution(url):
        pattern = r'(\d{2,4}x\d{2,4})\.mp4$'
        match = re.search(pattern, url)
        return match.group(1) if match else None

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        # Find the correct iframes
        video_urls = re.findall(r'<iframe .*?poster="(.*?)" src="(.*?)"', webpage)
        video_info_list = []

        for thumbnail, src in video_urls:
            media_param = re.search(r'media=(\d+)', src).group(1)
            info_url = f"https://dal.walla.co.il/media/{media_param}?origin=player.maariv.co.il"
            info_json = self._download_json(info_url, video_id)
            data = info_json['data']
            main_video_to_download_filename = data['video']['file_name']
            main_video_to_download_url = data['video']['url']
            duration_seconds = int(data['video']['duration'])

            format_list = [
                {
                    'format_id': '0',
                    'url': main_video_to_download_url,
                    'resolution': 'Main Video',
                }
            ]

            for format_id, stream_url_object in enumerate(data['video']['stream_urls'], start=1):
                stream_url = stream_url_object['stream_url']
                resolution = self.extract_resolution(stream_url)
                format_info = {
                    'format_id': str(format_id),
                    'url': stream_url,

Review comment (suggestion):
your regex matches past the end of the thumbnail url
so it gets `https://img.wcdn.co.il/3/6/1/1/3611585-46.jpg" style="width: 100%; height: 390px; border: 0;" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen`
trying to download that gives a http 400 (bad request) error

```suggestion
        video_urls = re.findall(r'<iframe [^>]?poster="([^"]+)"[^>]+ src="([^"]+)"', webpage)
```
`"([^"]+)"` checks for stuff between the "quotes" that isn't a quote, so then we only get the things in the `poster` or the `src`, and it doesnt overrun into other attributes

Code after:
    parse_resolution,
    unified_timestamp,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class MaarivIE(InfoExtractor):
    IE_NAME = 'maariv.co.il'
    _VALID_URL = r'https?://player\.maariv\.co\.il/public/player\.html\?(?:[^#]+&)?media=(?P<id>\d+)'
    _EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})']
    _TESTS = [{
        'url': 'https://player.maariv.co.il/public/player.html?player=maariv-desktop&media=3611585',
        'info_dict': {
            'id': '3611585',
            'duration': 75,
            'ext': 'mp4',
            'upload_date': '20231009',
            'title': 'מבצע חרבות ברזל',
            'timestamp': 1696851301,
        },
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.maariv.co.il/news/law/Article-1044008',
        'info_dict': {
            'id': '3611585',
            'duration': 75,
            'ext': 'mp4',
            'upload_date': '20231009',
            'title': 'מבצע חרבות ברזל',
            'timestamp': 1696851301,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        data = self._download_json(
            f'https://dal.walla.co.il/media/{video_id}?origin=player.maariv.co.il', video_id)['data']

        formats = []
        if hls_url := traverse_obj(data, ('video', 'url', {url_or_none})):
            formats.extend(self._extract_m3u8_formats(hls_url, video_id, m3u8_id='hls', fatal=False))

        for http_format in traverse_obj(data, ('video', 'stream_urls', ..., 'stream_url', {url_or_none})):
            formats.append({
                'url': http_format,
                'format_id': 'http',
                **parse_resolution(http_format),
            })

        return {