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