]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/expotv.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / expotv.py
CommitLineData
423817c4
PH
1from .common import InfoExtractor
2from ..utils import (
3 int_or_none,
4 unified_strdate,
5)
6
7
8class ExpoTVIE(InfoExtractor):
92519402 9 _VALID_URL = r'https?://(?:www\.)?expotv\.com/videos/[^?#]*/(?P<id>[0-9]+)($|[?#])'
423817c4 10 _TEST = {
e97c55ee
S
11 'url': 'http://www.expotv.com/videos/reviews/3/40/NYX-Butter-lipstick/667916',
12 'md5': 'fe1d728c3a813ff78f595bc8b7a707a8',
423817c4 13 'info_dict': {
e97c55ee 14 'id': '667916',
423817c4 15 'ext': 'mp4',
e97c55ee
S
16 'title': 'NYX Butter Lipstick Little Susie',
17 'description': 'Goes on like butter, but looks better!',
ec85ded8 18 'thumbnail': r're:^https?://.*\.jpg$',
e97c55ee
S
19 'uploader': 'Stephanie S.',
20 'upload_date': '20150520',
21 'view_count': int,
423817c4
PH
22 }
23 }
24
25 def _real_extract(self, url):
e97c55ee 26 video_id = self._match_id(url)
423817c4
PH
27
28 webpage = self._download_webpage(url, video_id)
29 player_key = self._search_regex(
30 r'<param name="playerKey" value="([^"]+)"', webpage, 'player key')
423817c4 31 config = self._download_json(
7d49502a
S
32 'http://client.expotv.com/video/config/%s/%s' % (video_id, player_key),
33 video_id, 'Downloading video configuration')
423817c4 34
03e3b4e1 35 formats = []
36 for fcfg in config['sources']:
7d49502a
S
37 media_url = fcfg.get('file')
38 if not media_url:
39 continue
40 if fcfg.get('type') == 'm3u8':
41 formats.extend(self._extract_m3u8_formats(
42 media_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls'))
03e3b4e1 43 else:
44 formats.append({
7d49502a 45 'url': media_url,
03e3b4e1 46 'height': int_or_none(fcfg.get('height')),
47 'format_id': fcfg.get('label'),
48 'ext': self._search_regex(
7d49502a
S
49 r'filename=.*\.([a-z0-9_A-Z]+)&', media_url,
50 'file extension', default=None) or fcfg.get('type'),
03e3b4e1 51 })
423817c4
PH
52
53 title = self._og_search_title(webpage)
54 description = self._og_search_description(webpage)
55 thumbnail = config.get('image')
56 view_count = int_or_none(self._search_regex(
57 r'<h5>Plays: ([0-9]+)</h5>', webpage, 'view counts'))
58 uploader = self._search_regex(
59 r'<div class="reviewer">\s*<img alt="([^"]+)"', webpage, 'uploader',
60 fatal=False)
61 upload_date = unified_strdate(self._search_regex(
62 r'<h5>Reviewed on ([0-9/.]+)</h5>', webpage, 'upload date',
e97c55ee 63 fatal=False), day_first=False)
423817c4
PH
64
65 return {
66 'id': video_id,
67 'formats': formats,
68 'title': title,
69 'description': description,
70 'view_count': view_count,
71 'thumbnail': thumbnail,
72 'uploader': uploader,
73 'upload_date': upload_date,
74 }