]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/breakcom.py
[lynda] Modernize and make more robust
[yt-dlp.git] / youtube_dl / extractor / breakcom.py
CommitLineData
ebfe352b
JMF
1from __future__ import unicode_literals
2
825e0984 3import re
67ae7b47 4import json
825e0984
PH
5
6from .common import InfoExtractor
d397c0b3
S
7from ..utils import (
8 int_or_none,
9 parse_age_limit,
10)
825e0984
PH
11
12
13class BreakIE(InfoExtractor):
f78c01f6
S
14 _VALID_URL = r'http://(?:www\.)?break\.com/video/(?:[^/]+/)*.+-(?P<id>\d+)'
15 _TESTS = [{
ebfe352b 16 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
ebfe352b
JMF
17 'info_dict': {
18 'id': '2468056',
19 'ext': 'mp4',
20 'title': 'When Girls Act Like D-Bags',
d7bb8884 21 'age_limit': 13,
6f5ac90c 22 }
f78c01f6
S
23 }, {
24 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
25 'only_matching': True,
26 }]
825e0984
PH
27
28 def _real_extract(self, url):
f78c01f6
S
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(
31 'http://www.break.com/embed/%s' % video_id, video_id)
32 info = json.loads(self._search_regex(
33 r'var embedVars = ({.*})\s*?</script>',
34 webpage, 'info json', flags=re.DOTALL))
d397c0b3 35
659eb98a
JMF
36 youtube_id = info.get('youtubeId')
37 if youtube_id:
38 return self.url_result(youtube_id, 'Youtube')
39
d397c0b3
S
40 formats = [{
41 'url': media['uri'] + '?' + info['AuthToken'],
42 'tbr': media['bitRate'],
43 'width': media['width'],
44 'height': media['height'],
dd7831fe 45 } for media in info['media'] if media.get('mediaPurpose') == 'play']
d397c0b3
S
46
47 if not formats:
48 formats.append({
49 'url': info['videoUri']
50 })
51
52 self._sort_formats(formats)
53
54 duration = int_or_none(info.get('videoLengthInSeconds'))
55 age_limit = parse_age_limit(info.get('audienceRating'))
56
ebfe352b
JMF
57 return {
58 'id': video_id,
ebfe352b 59 'title': info['contentName'],
67ae7b47 60 'thumbnail': info['thumbUri'],
d397c0b3
S
61 'duration': duration,
62 'age_limit': age_limit,
63 'formats': formats,
ebfe352b 64 }