]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hbo.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
16 class HBOBaseIE(InfoExtractor
):
56 def _extract_from_id(self
, video_id
):
57 video_data
= self
._download
_xml
(
58 'http://render.lv3.hbo.com/data/content/global/videos/data/%s.xml' % video_id
, video_id
)
59 title
= xpath_text(video_data
, 'title', 'title', True)
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 # #EXT-X-BYTERANGE is not supported by native hls downloader
97 # formats.extend(self._extract_m3u8_formats(
98 # video_url.replace('.tar', '/base_index.m3u8'),
99 # video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
101 elif source
.tag
== 'dash':
102 formats
.extend(self
._extract
_mpd
_formats
(
103 video_url
.replace('.tar', '/manifest.mpd'),
104 video_id
, mpd_id
='dash', fatal
=False))
106 format_info
= self
._FORMATS
_INFO
.get(source
.tag
, {})
108 'format_id': 'http-%s' % source
.tag
,
110 'width': format_info
.get('width'),
111 'height': format_info
.get('height'),
113 self
._sort
_formats
(formats
, ('width', 'height', 'tbr', 'format_id'))
116 card_sizes
= xpath_element(video_data
, 'titleCardSizes')
117 if card_sizes
is not None:
118 for size
in card_sizes
:
119 path
= xpath_text(size
, 'path')
122 width
= int_or_none(size
.get('width'))
132 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
134 'thumbnails': thumbnails
,
138 class HBOIE(HBOBaseIE
):
140 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/video/video\.html\?.*vid=(?P<id>[0-9]+)'
142 'url': 'http://www.hbo.com/video/video.html?autoplay=true&g=u&vid=1437839',
143 'md5': '2c6a6bc1222c7e91cb3334dad1746e5a',
147 'title': 'Ep. 64 Clip: Encryption',
148 'thumbnail': r
're:https?://.*\.jpg$',
153 def _real_extract(self
, url
):
154 video_id
= self
._match
_id
(url
)
155 return self
._extract
_from
_id
(video_id
)
158 class HBOEpisodeIE(HBOBaseIE
):
159 IE_NAME
= 'hbo:episode'
160 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?P<path>(?!video)(?:(?:[^/]+/)+video|watch-free-episodes)/(?P<id>[0-9a-z-]+))(?:\.html)?'
163 'url': 'http://www.hbo.com/girls/episodes/5/52-i-love-you-baby/video/ep-52-inside-the-episode.html?autoplay=true',
164 'md5': '61ead79b9c0dfa8d3d4b07ef4ac556fb',
167 'display_id': 'ep-52-inside-the-episode',
169 'title': 'Ep. 52: Inside the Episode',
170 'thumbnail': r
're:https?://.*\.jpg$',
174 'url': 'http://www.hbo.com/game-of-thrones/about/video/season-5-invitation-to-the-set.html?autoplay=true',
175 'only_matching': True,
177 'url': 'http://www.hbo.com/watch-free-episodes/last-week-tonight-with-john-oliver',
178 'only_matching': True,
181 def _real_extract(self
, url
):
182 path
, display_id
= re
.match(self
._VALID
_URL
, url
).groups()
184 content
= self
._download
_json
(
185 'http://www.hbo.com/api/content/' + path
, display_id
)['content']
187 video_id
= compat_str((content
.get('parsed', {}).get(
188 'common:FullBleedVideo', {}) or content
['selectedEpisode'])['videoId'])
190 info_dict
= self
._extract
_from
_id
(video_id
)
191 info_dict
['display_id'] = display_id