[hbo] add support for free episode urls and new formats extraction(closes #12519)

This commit is contained in:
Remita Amine 2017-03-22 17:28:24 +01:00
parent 391d076d7c
commit ca5ed022e9
1 changed files with 37 additions and 8 deletions

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import ( from ..utils import (
xpath_text, xpath_text,
xpath_element, xpath_element,
@ -14,14 +15,26 @@ from ..utils import (
class HBOBaseIE(InfoExtractor): class HBOBaseIE(InfoExtractor):
_FORMATS_INFO = { _FORMATS_INFO = {
'pro7': {
'width': 1280,
'height': 720,
},
'1920': { '1920': {
'width': 1280, 'width': 1280,
'height': 720, 'height': 720,
}, },
'pro6': {
'width': 768,
'height': 432,
},
'640': { '640': {
'width': 768, 'width': 768,
'height': 432, 'height': 432,
}, },
'pro5': {
'width': 640,
'height': 360,
},
'highwifi': { 'highwifi': {
'width': 640, 'width': 640,
'height': 360, 'height': 360,
@ -78,6 +91,17 @@ class HBOBaseIE(InfoExtractor):
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
video_url.replace('.tar', '/base_index_w8.m3u8'), video_url.replace('.tar', '/base_index_w8.m3u8'),
video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
elif source.tag == 'hls':
# #EXT-X-BYTERANGE is not supported by native hls downloader
# and ffmpeg (#10955)
# formats.extend(self._extract_m3u8_formats(
# video_url.replace('.tar', '/base_index.m3u8'),
# video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
continue
elif source.tag == 'dash':
formats.extend(self._extract_mpd_formats(
video_url.replace('.tar', '/manifest.mpd'),
video_id, mpd_id='dash', fatal=False))
else: else:
format_info = self._FORMATS_INFO.get(source.tag, {}) format_info = self._FORMATS_INFO.get(source.tag, {})
formats.append({ formats.append({
@ -112,10 +136,11 @@ class HBOBaseIE(InfoExtractor):
class HBOIE(HBOBaseIE): class HBOIE(HBOBaseIE):
IE_NAME = 'hbo'
_VALID_URL = r'https?://(?:www\.)?hbo\.com/video/video\.html\?.*vid=(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?hbo\.com/video/video\.html\?.*vid=(?P<id>[0-9]+)'
_TEST = { _TEST = {
'url': 'http://www.hbo.com/video/video.html?autoplay=true&g=u&vid=1437839', 'url': 'http://www.hbo.com/video/video.html?autoplay=true&g=u&vid=1437839',
'md5': '1c33253f0c7782142c993c0ba62a8753', 'md5': '2c6a6bc1222c7e91cb3334dad1746e5a',
'info_dict': { 'info_dict': {
'id': '1437839', 'id': '1437839',
'ext': 'mp4', 'ext': 'mp4',
@ -131,11 +156,12 @@ class HBOIE(HBOBaseIE):
class HBOEpisodeIE(HBOBaseIE): class HBOEpisodeIE(HBOBaseIE):
_VALID_URL = r'https?://(?:www\.)?hbo\.com/(?!video)([^/]+/)+video/(?P<id>[0-9a-z-]+)\.html' IE_NAME = 'hbo:episode'
_VALID_URL = r'https?://(?:www\.)?hbo\.com/(?P<path>(?!video)(?:(?:[^/]+/)+video|watch-free-episodes)/(?P<id>[0-9a-z-]+))(?:\.html)?'
_TESTS = [{ _TESTS = [{
'url': 'http://www.hbo.com/girls/episodes/5/52-i-love-you-baby/video/ep-52-inside-the-episode.html?autoplay=true', 'url': 'http://www.hbo.com/girls/episodes/5/52-i-love-you-baby/video/ep-52-inside-the-episode.html?autoplay=true',
'md5': '689132b253cc0ab7434237fc3a293210', 'md5': '61ead79b9c0dfa8d3d4b07ef4ac556fb',
'info_dict': { 'info_dict': {
'id': '1439518', 'id': '1439518',
'display_id': 'ep-52-inside-the-episode', 'display_id': 'ep-52-inside-the-episode',
@ -147,16 +173,19 @@ class HBOEpisodeIE(HBOBaseIE):
}, { }, {
'url': 'http://www.hbo.com/game-of-thrones/about/video/season-5-invitation-to-the-set.html?autoplay=true', 'url': 'http://www.hbo.com/game-of-thrones/about/video/season-5-invitation-to-the-set.html?autoplay=true',
'only_matching': True, 'only_matching': True,
}, {
'url': 'http://www.hbo.com/watch-free-episodes/last-week-tonight-with-john-oliver',
'only_matching': True,
}] }]
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) path, display_id = re.match(self._VALID_URL, url).groups()
webpage = self._download_webpage(url, display_id) content = self._download_json(
'http://www.hbo.com/api/content/' + path, display_id)['content']
video_id = self._search_regex( video_id = compat_str((content.get('parsed', {}).get(
r'(?P<q1>[\'"])videoId(?P=q1)\s*:\s*(?P<q2>[\'"])(?P<video_id>\d+)(?P=q2)', 'common:FullBleedVideo', {}) or content['selectedEpisode'])['videoId'])
webpage, 'video ID', group='video_id')
info_dict = self._extract_from_id(video_id) info_dict = self._extract_from_id(video_id)
info_dict['display_id'] = display_id info_dict['display_id'] = display_id