]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/hbo.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class HBOIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?:video|embed)(?:/[^/]+)*/(?P<id>[^/?#]+)'
20 'url': 'https://www.hbo.com/video/game-of-thrones/seasons/season-8/videos/trailer',
21 'md5': '8126210656f433c452a21367f9ad85b3',
25 'title': 'Game of Thrones - Trailer',
27 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
68 def _real_extract(self
, url
):
69 display_id
= self
._match
_id
(url
)
70 webpage
= self
._download
_webpage
(url
, display_id
)
71 location_path
= self
._parse
_json
(self
._html
_search
_regex
(
72 r
'data-state="({.+?})"', webpage
, 'state'), display_id
)['video']['locationUrl']
73 video_data
= self
._download
_xml
(urljoin(url
, location_path
), display_id
)
74 video_id
= xpath_text(video_data
, 'id', fatal
=True)
75 episode_title
= title
= xpath_text(video_data
, 'title', fatal
=True)
76 series
= xpath_text(video_data
, 'program')
78 title
= '%s - %s' % (series
, title
)
81 for source
in xpath_element(video_data
, 'videos', 'sources', True):
82 if source
.tag
== 'size':
83 path
= xpath_text(source
, './/path')
86 width
= source
.attrib
.get('width')
87 format_info
= self
._FORMATS
_INFO
.get(width
, {})
88 height
= format_info
.get('height')
91 'format_id': 'http%s' % ('-%dp' % height
if height
else ''),
92 'width': format_info
.get('width'),
95 rtmp
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', path
)
98 'url': rtmp
.group('url'),
99 'play_path': rtmp
.group('playpath'),
100 'app': rtmp
.group('app'),
102 'format_id': fmt
['format_id'].replace('http', 'rtmp'),
106 video_url
= source
.text
109 if source
.tag
== 'tarball':
110 formats
.extend(self
._extract
_m
3u8_formats
(
111 video_url
.replace('.tar', '/base_index_w8.m3u8'),
112 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False))
113 elif source
.tag
== 'hls':
114 m3u8_formats
= self
._extract
_m
3u8_formats
(
115 video_url
.replace('.tar', '/base_index.m3u8'),
116 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False)
117 for f
in m3u8_formats
:
118 if f
.get('vcodec') == 'none' and not f
.get('tbr'):
119 f
['tbr'] = int_or_none(self
._search
_regex
(
120 r
'-(\d+)k/', f
['url'], 'tbr', default
=None))
121 formats
.extend(m3u8_formats
)
122 elif source
.tag
== 'dash':
123 formats
.extend(self
._extract
_mpd
_formats
(
124 video_url
.replace('.tar', '/manifest.mpd'),
125 video_id
, mpd_id
='dash', fatal
=False))
127 format_info
= self
._FORMATS
_INFO
.get(source
.tag
, {})
129 'format_id': 'http-%s' % source
.tag
,
131 'width': format_info
.get('width'),
132 'height': format_info
.get('height'),
134 self
._sort
_formats
(formats
)
137 card_sizes
= xpath_element(video_data
, 'titleCardSizes')
138 if card_sizes
is not None:
139 for size
in card_sizes
:
140 path
= xpath_text(size
, 'path')
143 width
= int_or_none(size
.get('width'))
151 caption_url
= xpath_text(video_data
, 'captionUrl')
163 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
165 'episode': episode_title
,
167 'thumbnails': thumbnails
,
168 'subtitles': subtitles
,