]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/breakcom.py
5a87c2661910303d638351a0f5155dd20db35793
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
13 class BreakIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?(?P<site>break|screenjunkies)\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)'
16 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
20 'title': 'When Girls Act Like D-Bags',
24 'url': 'http://www.screenjunkies.com/video/best-quentin-tarantino-movie-2841915',
25 'md5': '5c2b686bec3d43de42bde9ec047536b0',
28 'display_id': 'best-quentin-tarantino-movie',
30 'title': 'Best Quentin Tarantino Movie',
31 'thumbnail': r
're:^https?://.*\.jpg',
37 'url': 'http://www.screenjunkies.com/video/honest-trailers-the-dark-knight',
40 'display_id': 'honest-trailers-the-dark-knight',
42 'title': 'Honest Trailers - The Dark Knight',
43 'thumbnail': r
're:^https?://.*\.(?:jpg|png)',
48 # requires subscription but worked around
49 'url': 'http://www.screenjunkies.com/video/knocking-dead-ep-1-the-show-so-far-3003285',
52 'display_id': 'knocking-dead-ep-1-the-show-so-far',
54 'title': 'State of The Dead Recap: Knocking Dead Pilot',
55 'thumbnail': r
're:^https?://.*\.jpg',
61 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
62 'only_matching': True,
65 _DEFAULT_BITRATES
= (48, 150, 320, 496, 864, 2240, 3264)
67 def _real_extract(self
, url
):
68 site
, display_id
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
71 webpage
= self
._download
_webpage
(url
, display_id
)
72 video_id
= self
._search
_regex
(
73 (r
'src=["\']/embed
/(\d
+)', r'data
-video
-content
-id=["\'](\d+)'),
76 webpage = self._download_webpage(
77 'http://www.%s.com/embed/%s' % (site, video_id),
78 display_id, 'Downloading video embed page')
79 embed_vars = self._parse_json(
81 r'(?s)embedVars\s*=\s*({.+?})\s*</script>', webpage, 'embed vars'),
84 youtube_id = embed_vars.get('youtubeId')
86 return self.url_result(youtube_id, 'Youtube')
88 title = embed_vars['contentName']
92 for f in embed_vars.get('media', []):
93 if not f.get('uri') or f.get('mediaPurpose') != 'play':
95 bitrate = int_or_none(f.get('bitRate'))
97 bitrates.append(bitrate)
100 'format_id': 'http-%d' % bitrate if bitrate else 'http',
101 'width': int_or_none(f.get('width')),
102 'height': int_or_none(f.get('height')),
108 # When subscriptionLevel > 0, i.e. plus subscription is required
109 # media list will be empty. However, hds and hls uris are still
110 # available. We can grab them assuming bitrates to be default.
111 bitrates = self._DEFAULT_BITRATES
113 auth_token = embed_vars.get('AuthToken')
115 def construct_manifest_url(base_url, ext):
117 pieces.extend([compat_str(b) for b in bitrates])
118 pieces.append('_kbps.mp4.%s?%s' % (ext, auth_token))
119 return ','.join(pieces)
121 if bitrates and auth_token:
122 hds_url = embed_vars.get('hdsUri')
124 formats.extend(self._extract_f4m_formats(
125 construct_manifest_url(hds_url, 'f4m'),
126 display_id, f4m_id='hds', fatal=False))
127 hls_url = embed_vars.get('hlsUri')
129 formats.extend(self._extract_m3u8_formats(
130 construct_manifest_url(hls_url, 'm3u8'),
131 display_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
132 self._sort_formats(formats)
136 'display_id': display_id,
138 'thumbnail': embed_vars.get('thumbUri'),
139 'duration': int_or_none(embed_vars.get('videoLengthInSeconds')) or None,
140 'age_limit': parse_age_limit(embed_vars.get('audienceRating')),
141 'tags': embed_vars.get('tags', '').split(','),