[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / huffpost.py
blob69fdc34ef73373b7e8aae3d69290ce83596afe9c
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 determine_ext,
6 parse_duration,
7 unified_strdate,
11 class HuffPostIE(InfoExtractor):
12 IE_DESC = 'Huffington Post'
13 _VALID_URL = r'''(?x)
14 https?://(embed\.)?live\.huffingtonpost\.com/
15 (?:
16 r/segment/[^/]+/|
17 HPLEmbedPlayer/\?segmentId=
19 (?P<id>[0-9a-f]+)'''
20 _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>https?://embed\.live\.huffingtonpost\.com/.+?)\1']
22 _TEST = {
23 'url': 'http://live.huffingtonpost.com/r/segment/legalese-it/52dd3e4b02a7602131000677',
24 'md5': '55f5e8981c1c80a64706a44b74833de8',
25 'info_dict': {
26 'id': '52dd3e4b02a7602131000677',
27 'ext': 'mp4',
28 'title': 'Legalese It! with @MikeSacksHP',
29 'description': 'This week on Legalese It, Mike talks to David Bosco about his new book on the ICC, "Rough Justice," he also discusses the Virginia AG\'s historic stance on gay marriage, the execution of Edgar Tamayo, the ICC\'s delay of Kenya\'s President and more. ',
30 'duration': 1549,
31 'upload_date': '20140124',
33 'params': {
34 # m3u8 download
35 'skip_download': True,
37 'expected_warnings': ['HTTP Error 404: Not Found'],
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
43 api_url = 'http://embed.live.huffingtonpost.com/api/segments/%s.json' % video_id
44 data = self._download_json(api_url, video_id)['data']
46 video_title = data['title']
47 duration = parse_duration(data.get('running_time'))
48 upload_date = unified_strdate(
49 data.get('schedule', {}).get('starts_at') or data.get('segment_start_date_time'))
50 description = data.get('description')
52 thumbnails = []
53 for url in filter(None, data['images'].values()):
54 m = re.match(r'.*-([0-9]+x[0-9]+)\.', url)
55 if not m:
56 continue
57 thumbnails.append({
58 'url': url,
59 'resolution': m.group(1),
62 formats = []
63 sources = data.get('sources', {})
64 live_sources = list(sources.get('live', {}).items()) + list(sources.get('live_again', {}).items())
65 for key, url in live_sources:
66 ext = determine_ext(url)
67 if ext == 'm3u8':
68 formats.extend(self._extract_m3u8_formats(
69 url, video_id, ext='mp4', m3u8_id='hls', fatal=False))
70 elif ext == 'f4m':
71 formats.extend(self._extract_f4m_formats(
72 url + '?hdcore=2.9.5', video_id, f4m_id='hds', fatal=False))
73 else:
74 formats.append({
75 'format': key,
76 'format_id': key.replace('/', '.'),
77 'ext': 'mp4',
78 'url': url,
79 'vcodec': 'none' if key.startswith('audio/') else None,
82 return {
83 'id': video_id,
84 'title': video_title,
85 'description': description,
86 'formats': formats,
87 'duration': duration,
88 'upload_date': upload_date,
89 'thumbnails': thumbnails,