]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hbo.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class HBOBaseIE(InfoExtractor
):
56 def _extract_info(self
, url
, display_id
):
57 video_data
= self
._download
_xml
(url
, display_id
)
58 video_id
= xpath_text(video_data
, 'id', fatal
=True)
59 episode_title
= title
= xpath_text(video_data
, 'title', fatal
=True)
60 series
= xpath_text(video_data
, 'program')
62 title
= '%s - %s' % (series
, title
)
65 for source
in xpath_element(video_data
, 'videos', 'sources', True):
66 if source
.tag
== 'size':
67 path
= xpath_text(source
, './/path')
70 width
= source
.attrib
.get('width')
71 format_info
= self
._FORMATS
_INFO
.get(width
, {})
72 height
= format_info
.get('height')
75 'format_id': 'http%s' % ('-%dp' % height
if height
else ''),
76 'width': format_info
.get('width'),
79 rtmp
= re
.search(r
'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', path
)
82 'url': rtmp
.group('url'),
83 'play_path': rtmp
.group('playpath'),
84 'app': rtmp
.group('app'),
86 'format_id': fmt
['format_id'].replace('http', 'rtmp'),
90 video_url
= source
.text
93 if source
.tag
== 'tarball':
94 formats
.extend(self
._extract
_m
3u8_formats
(
95 video_url
.replace('.tar', '/base_index_w8.m3u8'),
96 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False))
97 elif source
.tag
== 'hls':
98 m3u8_formats
= self
._extract
_m
3u8_formats
(
99 video_url
.replace('.tar', '/base_index.m3u8'),
100 video_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', fatal
=False)
101 for f
in m3u8_formats
:
102 if f
.get('vcodec') == 'none' and not f
.get('tbr'):
103 f
['tbr'] = int_or_none(self
._search
_regex
(
104 r
'-(\d+)k/', f
['url'], 'tbr', default
=None))
105 formats
.extend(m3u8_formats
)
106 elif source
.tag
== 'dash':
107 formats
.extend(self
._extract
_mpd
_formats
(
108 video_url
.replace('.tar', '/manifest.mpd'),
109 video_id
, mpd_id
='dash', fatal
=False))
111 format_info
= self
._FORMATS
_INFO
.get(source
.tag
, {})
113 'format_id': 'http-%s' % source
.tag
,
115 'width': format_info
.get('width'),
116 'height': format_info
.get('height'),
118 self
._sort
_formats
(formats
)
121 card_sizes
= xpath_element(video_data
, 'titleCardSizes')
122 if card_sizes
is not None:
123 for size
in card_sizes
:
124 path
= xpath_text(size
, 'path')
127 width
= int_or_none(size
.get('width'))
135 caption_url
= xpath_text(video_data
, 'captionUrl')
147 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
149 'episode': episode_title
,
151 'thumbnails': thumbnails
,
152 'subtitles': subtitles
,
156 class HBOIE(HBOBaseIE
):
158 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?:video|embed)(?:/[^/]+)*/(?P<id>[^/?#]+)'
160 'url': 'https://www.hbo.com/video/game-of-thrones/seasons/season-8/videos/trailer',
161 'md5': '8126210656f433c452a21367f9ad85b3',
165 'title': 'Game of Thrones - Trailer',
167 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
170 def _real_extract(self
, url
):
171 display_id
= self
._match
_id
(url
)
172 webpage
= self
._download
_webpage
(url
, display_id
)
173 location_path
= self
._parse
_json
(self
._html
_search
_regex
(
174 r
'data-state="({.+?})"', webpage
, 'state'), display_id
)['video']['locationUrl']
175 return self
._extract
_info
(urljoin(url
, location_path
), display_id
)