]>
Commit | Line | Data |
---|---|---|
ebfe352b JMF |
1 | from __future__ import unicode_literals |
2 | ||
825e0984 | 3 | import re |
67ae7b47 | 4 | import json |
825e0984 PH |
5 | |
6 | from .common import InfoExtractor | |
d397c0b3 S |
7 | from ..utils import ( |
8 | int_or_none, | |
9 | parse_age_limit, | |
10 | ) | |
825e0984 PH |
11 | |
12 | ||
13 | class 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', | |
6f5ac90c | 21 | } |
f78c01f6 S |
22 | }, { |
23 | 'url': 'http://www.break.com/video/ugc/baby-flex-2773063', | |
24 | 'only_matching': True, | |
25 | }] | |
825e0984 PH |
26 | |
27 | def _real_extract(self, url): | |
f78c01f6 S |
28 | video_id = self._match_id(url) |
29 | webpage = self._download_webpage( | |
30 | 'http://www.break.com/embed/%s' % video_id, video_id) | |
31 | info = json.loads(self._search_regex( | |
32 | r'var embedVars = ({.*})\s*?</script>', | |
33 | webpage, 'info json', flags=re.DOTALL)) | |
d397c0b3 | 34 | |
659eb98a JMF |
35 | youtube_id = info.get('youtubeId') |
36 | if youtube_id: | |
37 | return self.url_result(youtube_id, 'Youtube') | |
38 | ||
d397c0b3 S |
39 | formats = [{ |
40 | 'url': media['uri'] + '?' + info['AuthToken'], | |
41 | 'tbr': media['bitRate'], | |
42 | 'width': media['width'], | |
43 | 'height': media['height'], | |
dd7831fe | 44 | } for media in info['media'] if media.get('mediaPurpose') == 'play'] |
d397c0b3 S |
45 | |
46 | if not formats: | |
47 | formats.append({ | |
48 | 'url': info['videoUri'] | |
49 | }) | |
50 | ||
51 | self._sort_formats(formats) | |
52 | ||
53 | duration = int_or_none(info.get('videoLengthInSeconds')) | |
54 | age_limit = parse_age_limit(info.get('audienceRating')) | |
55 | ||
ebfe352b JMF |
56 | return { |
57 | 'id': video_id, | |
ebfe352b | 58 | 'title': info['contentName'], |
67ae7b47 | 59 | 'thumbnail': info['thumbUri'], |
d397c0b3 S |
60 | 'duration': duration, |
61 | 'age_limit': age_limit, | |
62 | 'formats': formats, | |
ebfe352b | 63 | } |