]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/breakcom.py
[cleanup] Misc fixes
[yt-dlp.git] / yt_dlp / extractor / breakcom.py
1 from __future__ import unicode_literals
2
3
4 from .common import InfoExtractor
5 from .youtube import YoutubeIE
6 from ..utils import (
7 int_or_none,
8 url_or_none,
9 )
10
11
12 class BreakIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?break\.com/video/(?P<display_id>[^/]+?)(?:-(?P<id>\d+))?(?:[/?#&]|$)'
14 _TESTS = [{
15 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056',
16 'info_dict': {
17 'id': '2468056',
18 'ext': 'mp4',
19 'title': 'When Girls Act Like D-Bags',
20 'age_limit': 13,
21 },
22 }, {
23 # youtube embed
24 'url': 'http://www.break.com/video/someone-forgot-boat-brakes-work',
25 'info_dict': {
26 'id': 'RrrDLdeL2HQ',
27 'ext': 'mp4',
28 'title': 'Whale Watching Boat Crashing Into San Diego Dock',
29 'description': 'md5:afc1b2772f0a8468be51dd80eb021069',
30 'upload_date': '20160331',
31 'uploader': 'Steve Holden',
32 'uploader_id': 'sdholden07',
33 },
34 'params': {
35 'skip_download': True,
36 }
37 }, {
38 'url': 'http://www.break.com/video/ugc/baby-flex-2773063',
39 'only_matching': True,
40 }]
41
42 def _real_extract(self, url):
43 display_id, video_id = self._match_valid_url(url).groups()
44
45 webpage = self._download_webpage(url, display_id)
46
47 youtube_url = YoutubeIE._extract_url(webpage)
48 if youtube_url:
49 return self.url_result(youtube_url, ie=YoutubeIE.ie_key())
50
51 content = self._parse_json(
52 self._search_regex(
53 r'(?s)content["\']\s*:\s*(\[.+?\])\s*[,\n]', webpage,
54 'content'),
55 display_id)
56
57 formats = []
58 for video in content:
59 video_url = url_or_none(video.get('url'))
60 if not video_url:
61 continue
62 bitrate = int_or_none(self._search_regex(
63 r'(\d+)_kbps', video_url, 'tbr', default=None))
64 formats.append({
65 'url': video_url,
66 'format_id': 'http-%d' % bitrate if bitrate else 'http',
67 'tbr': bitrate,
68 })
69 self._sort_formats(formats)
70
71 title = self._search_regex(
72 (r'title["\']\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
73 r'<h1[^>]*>(?P<value>[^<]+)'), webpage, 'title', group='value')
74
75 def get(key, name):
76 return int_or_none(self._search_regex(
77 r'%s["\']\s*:\s*["\'](\d+)' % key, webpage, name,
78 default=None))
79
80 age_limit = get('ratings', 'age limit')
81 video_id = video_id or get('pid', 'video id') or display_id
82
83 return {
84 'id': video_id,
85 'display_id': display_id,
86 'title': title,
87 'thumbnail': self._og_search_thumbnail(webpage),
88 'age_limit': age_limit,
89 'formats': formats,
90 }