]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/plays.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / plays.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 class PlaysTVIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?plays\.tv/(?:video|embeds)/(?P<id>[0-9a-f]{18})'
9 _TESTS = [{
10 'url': 'https://plays.tv/video/56af17f56c95335490/when-you-outplay-the-azir-wall',
11 'md5': 'dfeac1198506652b5257a62762cec7bc',
12 'info_dict': {
13 'id': '56af17f56c95335490',
14 'ext': 'mp4',
15 'title': 'Bjergsen - When you outplay the Azir wall',
16 'description': 'Posted by Bjergsen',
17 }
18 }, {
19 'url': 'https://plays.tv/embeds/56af17f56c95335490',
20 'only_matching': True,
21 }]
22
23 def _real_extract(self, url):
24 video_id = self._match_id(url)
25 webpage = self._download_webpage(
26 'https://plays.tv/video/%s' % video_id, video_id)
27
28 info = self._search_json_ld(webpage, video_id,)
29
30 mpd_url, sources = re.search(
31 r'(?s)<video[^>]+data-mpd="([^"]+)"[^>]*>(.+?)</video>',
32 webpage).groups()
33 formats = self._extract_mpd_formats(
34 self._proto_relative_url(mpd_url), video_id, mpd_id='DASH')
35 for format_id, height, format_url in re.findall(r'<source\s+res="((\d+)h?)"\s+src="([^"]+)"', sources):
36 formats.append({
37 'url': self._proto_relative_url(format_url),
38 'format_id': 'http-' + format_id,
39 'height': int_or_none(height),
40 })
41
42 info.update({
43 'id': video_id,
44 'description': self._og_search_description(webpage),
45 'thumbnail': info.get('thumbnail') or self._og_search_thumbnail(webpage),
46 'formats': formats,
47 })
48
49 return info