3 from .common
import InfoExtractor
13 class HBOBaseIE(InfoExtractor
):
53 def _extract_info(self
, url
, display_id
):
54 video_data
= self
._download
_xml
(url
, display_id
)
55 video_id
= xpath_text(video_data
, 'id', fatal
=True)
56 episode_title
= title
= xpath_text(video_data
, 'title', fatal
=True)
57 series
= xpath_text(video_data
, 'program')
59 title
= '%s - %s' % (series
, title
)
62 for source
in xpath_element(video_data
, 'videos', 'sources', True):
63 if source
.tag
== 'size':
64 path
= xpath_text(source
, './/path')
67 width
= source
.attrib
.get('width')
68 format_info
= self
._FORMATS
_INFO
.get(width
, {})
69 height
= format_info
.get('height')
72 'format_id': 'http%s' % ('-%dp' % height
if height
else ''),
73 'width': format_info
.get('width'),
76 rtmp
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', path
)
79 'url': rtmp
.group('url'),
80 'play_path': rtmp
.group('playpath'),
81 'app': rtmp
.group('app'),
83 'format_id': fmt
['format_id'].replace('http', 'rtmp'),
87 video_url
= source
.text
90 if source
.tag
== 'tarball':
91 formats
.extend(self
._extract
_m
3u8_formats
(
92 video_url
.replace('.tar', '/base_index_w8.m3u8'),
93 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False))
94 elif source
.tag
== 'hls':
95 m3u8_formats
= self
._extract
_m
3u8_formats
(
96 video_url
.replace('.tar', '/base_index.m3u8'),
97 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False)
98 for f
in m3u8_formats
:
99 if f
.get('vcodec') == 'none' and not f
.get('tbr'):
100 f
['tbr'] = int_or_none(self
._search
_regex
(
101 r
'-(\d+)k/', f
['url'], 'tbr', default
=None))
102 formats
.extend(m3u8_formats
)
103 elif source
.tag
== 'dash':
104 formats
.extend(self
._extract
_mpd
_formats
(
105 video_url
.replace('.tar', '/manifest.mpd'),
106 video_id
, mpd_id
='dash', fatal
=False))
108 format_info
= self
._FORMATS
_INFO
.get(source
.tag
, {})
110 'format_id': 'http-%s' % source
.tag
,
112 'width': format_info
.get('width'),
113 'height': format_info
.get('height'),
117 card_sizes
= xpath_element(video_data
, 'titleCardSizes')
118 if card_sizes
is not None:
119 for size
in card_sizes
:
120 path
= xpath_text(size
, 'path')
123 width
= int_or_none(size
.get('width'))
131 caption_url
= xpath_text(video_data
, 'captionUrl')
143 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
145 'episode': episode_title
,
147 'thumbnails': thumbnails
,
148 'subtitles': subtitles
,
152 class HBOIE(HBOBaseIE
):
154 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?:video|embed)(?:/[^/]+)*/(?P<id>[^/?#]+)'
156 'url': 'https://www.hbo.com/video/game-of-thrones/seasons/season-8/videos/trailer',
157 'md5': '8126210656f433c452a21367f9ad85b3',
161 'title': 'Game of Thrones - Trailer',
163 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
166 def _real_extract(self
, url
):
167 display_id
= self
._match
_id
(url
)
168 webpage
= self
._download
_webpage
(url
, display_id
)
169 location_path
= self
._parse
_json
(self
._html
_search
_regex
(
170 r
'data-state="({.+?})"', webpage
, 'state'), display_id
)['video']['locationUrl']
171 return self
._extract
_info
(urljoin(url
, location_path
), display_id
)