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

Code before:
            if f['vcodec'] != 'none' and quality in f['url']:
                http_url = '%s%s.mp4' % (self._HOST, quality)

                urlh = self._request_webpage(
                    HEADRequest(http_url), quality,
                    note='Check filesize', fatal=False)
                if urlh:
                    http_f = f.copy()
                    del http_f['manifest_url']
                    http_f.update({
                        'format_id': http_f['format_id'].replace('hls-', 'https-'),
                        'url': http_url,
                        'protocol': 'https',
                        'filesize_approx': int_or_none(urlh.headers.get('Content-Length', None)),
                    })
                    return http_f
                return None

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

        if not url.startswith('http'):
            url = '%s//%s' % (self.http_scheme(), url)

        webpage = self._download_webpage(url, video_id)
        video_path = self._search_regex(r'akamaihd\.net/i(?:/,)?(/content/.*?)\.mp4', webpage, 'video_path')

        formats = self._extract_mpd_formats(
            f'{self._HOST}/local/dash/,{video_path}.mp4.urlset/manifest.mpd',
            video_id, mpd_id='dash', fatal=False)
        m3u8_formats = self._extract_m3u8_formats(
            f'{self._HOST}/local/hls/,{video_path}.mp4.urlset/master.m3u8',
            video_id, 'mp4', m3u8_id='hls', fatal=False)
        formats.extend(m3u8_formats)

        for q in filter(None, video_path.split(',')):
            http_f = self._generate_mp4_url(q, m3u8_formats)
            if http_f:
                formats.append(http_f)

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._og_search_title(webpage, default=None),
            'description': self._og_search_description(webpage, default=None),
            'thumbnail': self._og_search_thumbnail(webpage, default=None),
            'formats': formats,
            'upload_date': unified_strdate(self._search_regex(r'datetime="(.+?)"', webpage, 'upload_date', fatal=False))
        }


Review comment (suggestion):
In the source page `akamaihd.net/i` is just used as a fake placeholder URI that will be replaced with the real one according to the logic reported below.

Thus I wouldn't match this URI since it has high chance to be changed in the future. Instead I would match the url that ends with m3u8.
```
self._search_regex(r'(/content/\S*?)\.mp4\S*?m3u8', webpage, 'video_path')
```


URI replace logic used today by `la7.it`:

```
         case 'mp4':
                e.akamai.mp4 = n.replace('vodpmd.la7.it.edgesuite.net/', 'awsvodpkg.iltrovatore.it/'),
                e.akamai.mp4.indexOf('http:') < 0 ? e.akamai.mp4 = 'https:' + e.akamai.mp4 : e.akamai.mp4 = e.akamai.mp4.replace('http:', ''),
                e.ilTrovatore.mp4 = n.replace('vodpmd.la7.it.edgesuite.net/', 'vodpkg.iltrovatore.it/local/mp4/');
                break;
              case 'm3u8':
                e.akamai.m3u8 = n.replace('la7-vh.akamaihd.net/i/', 'awsvodpkg.iltrovatore.it/local/hls/'),
                e.akamai.m3u8 = e.akamai.m3u8.replace('csmil', 'urlset'),
                e.akamai.m3u8 = 'https:' + e.akamai.m3u8,
                e.ilTrovatore.m3u8 = n.replace('la7-vh.akamaihd.net/i/', 'vodpkg.iltrovatore.it/local/hls/'),
                e.ilTrovatore.m3u8 = e.ilTrovatore.m3u8.replace('csmil', 'urlset'),
                e.akamai.dash = e.akamai.m3u8.replace('local/hls', 'local/dash/'),
                e.akamai.dash = e.akamai.dash.replace('master.m3u8', 'manifest.mpd'),
                e.ilTrovatore.dash = e.ilTrovatore.m3u8.replace('local/hls', 'local/dash/'),
                e.ilTrovatore.dash = e.ilTrovatore.dash.replace('master.m3u8', 'manifest.mpd');
                break;
              case 'f4m':
                break;
              case 'dash':
                e.akamai.dash = n.replace('la7-vh.akamaihd.net/i/', 'awsvodpkg.iltrovatore.it/local/dash/'),
                e.akamai.dash = e.akamai.dash.replace('csmil', 'urlset'),
                e.akamai.dash = e.akamai.dash.replace('master.m3u8', 'manifest.mpd'),
                e.akamai.dash = e.akamai.dash,
                e.ilTrovatore.dash = n.replace('la7-vh.akamaihd.net/i/', 'vodpkg.iltrovatore.it/local/dash/'),
                e.ilTrovatore.dash = e.ilTrovatore.dash.replace('csmil', 'urlset'),
                e.ilTrovatore.dash = e.ilTrovatore.dash.replace('master.m3u8', 'manifest.mpd')
            }
          }
 ```

Code after:
            'description': 'Il gol di Lindsey Thomas | Fiorentina vs Milan | Serie A Calcio Femminile',
            'thumbnail': 're:^https?://.*',
            'upload_date': '20221126',
            'formats': 'count:8',
        },
    }, {
        'url': 'http://www.la7.it/omnibus/rivedila7/omnibus-news-02-07-2016-189077',
        'only_matching': True,
    }]
    _HOST = 'https://awsvodpkg.iltrovatore.it'

    def _generate_mp4_url(self, quality, m3u8_formats):
        for f in m3u8_formats:
            if f['vcodec'] != 'none' and quality in f['url']:
                http_url = f'{self._HOST}{quality}.mp4'

                urlh = self._request_webpage(
                    HEADRequest(http_url), quality,
                    note='Check filesize', fatal=False)
                if urlh:
                    http_f = f.copy()
                    del http_f['manifest_url']
                    http_f.update({
                        'format_id': http_f['format_id'].replace('hls-', 'https-'),
                        'url': http_url,
                        'protocol': 'https',
                        'filesize_approx': int_or_none(urlh.headers.get('Content-Length', None)),
                    })
                    return http_f
                return None

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

        if re.search(r'(?i)(drmsupport\s*:\s*true)\s*', webpage):
            self.report_drm(video_id)

        video_path = self._search_regex(
            r'(/content/[\w/,]+?)\.mp4(?:\.csmil)?/master\.m3u8', webpage, 'video_path')

        formats = self._extract_mpd_formats(
            f'{self._HOST}/local/dash/,{video_path}.mp4.urlset/manifest.mpd',
            video_id, mpd_id='dash', fatal=False)
        m3u8_formats = self._extract_m3u8_formats(
            f'{self._HOST}/local/hls/,{video_path}.mp4.urlset/master.m3u8',
            video_id, 'mp4', m3u8_id='hls', fatal=False)
        formats.extend(m3u8_formats)

        for q in filter(None, video_path.split(',')):
            http_f = self._generate_mp4_url(q, m3u8_formats)