3 from .common
import InfoExtractor
14 class HBOBaseIE(InfoExtractor
):
54 def _extract_info(self
, url
, display_id
):
55 video_data
= self
._download
_xml
(url
, display_id
)
56 video_id
= xpath_text(video_data
, 'id', fatal
=True)
57 episode_title
= title
= xpath_text(video_data
, 'title', fatal
=True)
58 series
= xpath_text(video_data
, 'program')
60 title
= f
'{series} - {title}'
63 for source
in xpath_element(video_data
, 'videos', 'sources', True):
64 if source
.tag
== 'size':
65 path
= xpath_text(source
, './/path')
68 width
= source
.attrib
.get('width')
69 format_info
= self
._FORMATS
_INFO
.get(width
, {})
70 height
= format_info
.get('height')
73 'format_id': join_nonempty('http'. height
and f
'{height}p'),
74 'width': format_info
.get('width'),
77 rtmp
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', path
)
80 'url': rtmp
.group('url'),
81 'play_path': rtmp
.group('playpath'),
82 'app': rtmp
.group('app'),
84 'format_id': fmt
['format_id'].replace('http', 'rtmp'),
88 video_url
= source
.text
91 if source
.tag
== 'tarball':
92 formats
.extend(self
._extract
_m
3u8_formats
(
93 video_url
.replace('.tar', '/base_index_w8.m3u8'),
94 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False))
95 elif source
.tag
== 'hls':
96 m3u8_formats
= self
._extract
_m
3u8_formats
(
97 video_url
.replace('.tar', '/base_index.m3u8'),
98 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False)
99 for f
in m3u8_formats
:
100 if f
.get('vcodec') == 'none' and not f
.get('tbr'):
101 f
['tbr'] = int_or_none(self
._search
_regex
(
102 r
'-(\d+)k/', f
['url'], 'tbr', default
=None))
103 formats
.extend(m3u8_formats
)
104 elif source
.tag
== 'dash':
105 formats
.extend(self
._extract
_mpd
_formats
(
106 video_url
.replace('.tar', '/manifest.mpd'),
107 video_id
, mpd_id
='dash', fatal
=False))
109 format_info
= self
._FORMATS
_INFO
.get(source
.tag
, {})
111 'format_id': f
'http-{source.tag}',
113 'width': format_info
.get('width'),
114 'height': format_info
.get('height'),
118 card_sizes
= xpath_element(video_data
, 'titleCardSizes')
119 if card_sizes
is not None:
120 for size
in card_sizes
:
121 path
= xpath_text(size
, 'path')
124 width
= int_or_none(size
.get('width'))
132 caption_url
= xpath_text(video_data
, 'captionUrl')
144 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
146 'episode': episode_title
,
148 'thumbnails': thumbnails
,
149 'subtitles': subtitles
,
153 class HBOIE(HBOBaseIE
):
155 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?:video|embed)(?:/[^/]+)*/(?P<id>[^/?#]+)'
157 'url': 'https://www.hbo.com/video/game-of-thrones/seasons/season-8/videos/trailer',
158 'md5': '8126210656f433c452a21367f9ad85b3',
162 'title': 'Game of Thrones - Trailer',
164 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
167 def _real_extract(self
, url
):
168 display_id
= self
._match
_id
(url
)
169 webpage
= self
._download
_webpage
(url
, display_id
)
170 location_path
= self
._parse
_json
(self
._html
_search
_regex
(
171 r
'data-state="({.+?})"', webpage
, 'state'), display_id
)['video']['locationUrl']
172 return self
._extract
_info
(urljoin(url
, location_path
), display_id
)