[breakcom] Fix extraction (closes #16254)

pull/2/head
Sergey M․ 7 years ago
parent 70d35d166c
commit 2441c1aab1
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

@ -3,15 +3,13 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from .youtube import YoutubeIE
from ..compat import compat_str from ..compat import compat_str
from ..utils import ( from ..utils import int_or_none
int_or_none,
parse_age_limit,
)
class BreakIE(InfoExtractor): class BreakIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?(?P<site>break|screenjunkies)\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)' _VALID_URL = r'https?://(?:www\.)?break\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)'
_TESTS = [{ _TESTS = [{
'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056', 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
'info_dict': { 'info_dict': {
@ -19,125 +17,73 @@ class BreakIE(InfoExtractor):
'ext': 'mp4', 'ext': 'mp4',
'title': 'When Girls Act Like D-Bags', 'title': 'When Girls Act Like D-Bags',
'age_limit': 13, 'age_limit': 13,
}
}, {
'url': 'http://www.screenjunkies.com/video/best-quentin-tarantino-movie-2841915',
'md5': '5c2b686bec3d43de42bde9ec047536b0',
'info_dict': {
'id': '2841915',
'display_id': 'best-quentin-tarantino-movie',
'ext': 'mp4',
'title': 'Best Quentin Tarantino Movie',
'thumbnail': r're:^https?://.*\.jpg',
'duration': 3671,
'age_limit': 13,
'tags': list,
},
}, {
'url': 'http://www.screenjunkies.com/video/honest-trailers-the-dark-knight',
'info_dict': {
'id': '2348808',
'display_id': 'honest-trailers-the-dark-knight',
'ext': 'mp4',
'title': 'Honest Trailers - The Dark Knight',
'thumbnail': r're:^https?://.*\.(?:jpg|png)',
'age_limit': 10,
'tags': list,
}, },
}, { }, {
# requires subscription but worked around # youtube embed
'url': 'http://www.screenjunkies.com/video/knocking-dead-ep-1-the-show-so-far-3003285', 'url': 'http://www.break.com/video/someone-forgot-boat-brakes-work',
'info_dict': { 'info_dict': {
'id': '3003285', 'id': 'RrrDLdeL2HQ',
'display_id': 'knocking-dead-ep-1-the-show-so-far',
'ext': 'mp4', 'ext': 'mp4',
'title': 'State of The Dead Recap: Knocking Dead Pilot', 'title': 'Whale Watching Boat Crashing Into San Diego Dock',
'thumbnail': r're:^https?://.*\.jpg', 'description': 'md5:afc1b2772f0a8468be51dd80eb021069',
'duration': 3307, 'upload_date': '20160331',
'age_limit': 13, 'uploader': 'Steve Holden',
'tags': list, 'uploader_id': 'sdholden07',
}, },
'params': {
'skip_download': True,
}
}, { }, {
'url': 'http://www.break.com/video/ugc/baby-flex-2773063', 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
'only_matching': True, 'only_matching': True,
}] }]
_DEFAULT_BITRATES = (48, 150, 320, 496, 864, 2240, 3264)
def _real_extract(self, url): def _real_extract(self, url):
site, display_id, video_id = re.match(self._VALID_URL, url).groups() display_id, video_id = re.match(self._VALID_URL, url).groups()
if not video_id: webpage = self._download_webpage(url, display_id)
webpage = self._download_webpage(url, display_id)
video_id = self._search_regex(
(r'src=["\']/embed/(\d+)', r'data-video-content-id=["\'](\d+)'),
webpage, 'video id')
webpage = self._download_webpage( youtube_url = YoutubeIE._extract_url(webpage)
'http://www.%s.com/embed/%s' % (site, video_id), if youtube_url:
display_id, 'Downloading video embed page') return self.url_result(youtube_url, ie=YoutubeIE.ie_key())
embed_vars = self._parse_json(
content = self._parse_json(
self._search_regex( self._search_regex(
r'(?s)embedVars\s*=\s*({.+?})\s*</script>', webpage, 'embed vars'), r'(?s)content["\']\s*:\s*(\[.+?\])\s*[,\n]', webpage,
'content'),
display_id) display_id)
youtube_id = embed_vars.get('youtubeId')
if youtube_id:
return self.url_result(youtube_id, 'Youtube')
title = embed_vars['contentName']
formats = [] formats = []
bitrates = [] for video in content:
for f in embed_vars.get('media', []): video_url = video.get('url')
if not f.get('uri') or f.get('mediaPurpose') != 'play': if not video_url or not isinstance(video_url, compat_str):
continue continue
bitrate = int_or_none(f.get('bitRate')) bitrate = int_or_none(self._search_regex(
if bitrate: r'(\d+)_kbps', video_url, 'tbr', default=None))
bitrates.append(bitrate)
formats.append({ formats.append({
'url': f['uri'], 'url': video_url,
'format_id': 'http-%d' % bitrate if bitrate else 'http', 'format_id': 'http-%d' % bitrate if bitrate else 'http',
'width': int_or_none(f.get('width')),
'height': int_or_none(f.get('height')),
'tbr': bitrate, 'tbr': bitrate,
'format': 'mp4',
}) })
self._sort_formats(formats)
if not bitrates: title = self._search_regex(
# When subscriptionLevel > 0, i.e. plus subscription is required (r'title["\']\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
# media list will be empty. However, hds and hls uris are still r'<h1[^>]*>(?P<value>[^<]+)'), webpage, 'title', group='value')
# available. We can grab them assuming bitrates to be default.
bitrates = self._DEFAULT_BITRATES
auth_token = embed_vars.get('AuthToken')
def construct_manifest_url(base_url, ext): def get(key, name):
pieces = [base_url] return int_or_none(self._search_regex(
pieces.extend([compat_str(b) for b in bitrates]) r'%s["\']\s*:\s*["\'](\d+)' % key, webpage, name,
pieces.append('_kbps.mp4.%s?%s' % (ext, auth_token)) default=None))
return ','.join(pieces)
if bitrates and auth_token: age_limit = get('ratings', 'age limit')
hds_url = embed_vars.get('hdsUri') video_id = video_id or get('pid', 'video id') or display_id
if hds_url:
formats.extend(self._extract_f4m_formats(
construct_manifest_url(hds_url, 'f4m'),
display_id, f4m_id='hds', fatal=False))
hls_url = embed_vars.get('hlsUri')
if hls_url:
formats.extend(self._extract_m3u8_formats(
construct_manifest_url(hls_url, 'm3u8'),
display_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'display_id': display_id, 'display_id': display_id,
'title': title, 'title': title,
'thumbnail': embed_vars.get('thumbUri'), 'thumbnail': self._og_search_thumbnail(webpage),
'duration': int_or_none(embed_vars.get('videoLengthInSeconds')) or None, 'age_limit': age_limit,
'age_limit': parse_age_limit(embed_vars.get('audienceRating')),
'tags': embed_vars.get('tags', '').split(','),
'formats': formats, 'formats': formats,
} }

Loading…
Cancel
Save