]>
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 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'),
115 self
._sort
_formats
(formats
)
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'))
134 'duration': parse_duration(xpath_text(video_data
, 'duration/tv14')),
136 'thumbnails': thumbnails
,
140 class HBOIE(HBOBaseIE
):
142 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/video/video\.html\?.*vid=(?P<id>[0-9]+)'
144 'url': 'http://www.hbo.com/video/video.html?autoplay=true&g=u&vid=1437839',
145 'md5': '2c6a6bc1222c7e91cb3334dad1746e5a',
149 'title': 'Ep. 64 Clip: Encryption',
150 'thumbnail': r
're:https?://.*\.jpg$',
155 def _real_extract(self
, url
):
156 video_id
= self
._match
_id
(url
)
157 return self
._extract
_from
_id
(video_id
)
160 class HBOEpisodeIE(HBOBaseIE
):
161 IE_NAME
= 'hbo:episode'
162 _VALID_URL
= r
'https?://(?:www\.)?hbo\.com/(?P<path>(?!video)(?:(?:[^/]+/)+video|watch-free-episodes)/(?P<id>[0-9a-z-]+))(?:\.html)?'
165 'url': 'http://www.hbo.com/girls/episodes/5/52-i-love-you-baby/video/ep-52-inside-the-episode.html?autoplay=true',
166 'md5': '61ead79b9c0dfa8d3d4b07ef4ac556fb',
169 'display_id': 'ep-52-inside-the-episode',
171 'title': 'Ep. 52: Inside the Episode',
172 'thumbnail': r
're:https?://.*\.jpg$',
176 'url': 'http://www.hbo.com/game-of-thrones/about/video/season-5-invitation-to-the-set.html?autoplay=true',
177 'only_matching': True,
179 'url': 'http://www.hbo.com/watch-free-episodes/last-week-tonight-with-john-oliver',
180 'only_matching': True,
183 def _real_extract(self
, url
):
184 path
, display_id
= re
.match(self
._VALID
_URL
, url
).groups()
186 content
= self
._download
_json
(
187 'http://www.hbo.com/api/content/' + path
, display_id
)['content']
189 video_id
= compat_str((content
.get('parsed', {}).get(
190 'common:FullBleedVideo', {}) or content
['selectedEpisode'])['videoId'])
192 info_dict
= self
._extract
_from
_id
(video_id
)
193 info_dict
['display_id'] = display_id