[ie/facebook] Support more groups URLs (#11576)
[yt-dlp3.git] / yt_dlp / extractor / r7.py
blob79a4c0a125e861b4a1d3bf16874dd0c1ebdc6da8
1 from .common import InfoExtractor
2 from ..utils import int_or_none
5 class R7IE(InfoExtractor):
6 _WORKING = False
7 _ENABLED = None # XXX: pass through to GenericIE
8 _VALID_URL = r'''(?x)
9 https?://
10 (?:
11 (?:[a-zA-Z]+)\.r7\.com(?:/[^/]+)+/idmedia/|
12 noticias\.r7\.com(?:/[^/]+)+/[^/]+-|
13 player\.r7\.com/video/i/
15 (?P<id>[\da-f]{24})
16 '''
17 _TESTS = [{
18 'url': 'http://videos.r7.com/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-/idmedia/54e7050b0cf2ff57e0279389.html',
19 'md5': '403c4e393617e8e8ddc748978ee8efde',
20 'info_dict': {
21 'id': '54e7050b0cf2ff57e0279389',
22 'ext': 'mp4',
23 'title': 'Policiais humilham suspeito à beira da morte: "Morre com dignidade"',
24 'description': 'md5:01812008664be76a6479aa58ec865b72',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'duration': 98,
27 'like_count': int,
28 'view_count': int,
30 }, {
31 'url': 'http://esportes.r7.com/videos/cigano-manda-recado-aos-fas/idmedia/4e176727b51a048ee6646a1b.html',
32 'only_matching': True,
33 }, {
34 'url': 'http://noticias.r7.com/record-news/video/representante-do-instituto-sou-da-paz-fala-sobre-fim-do-estatuto-do-desarmamento-5480fc580cf2285b117f438d/',
35 'only_matching': True,
36 }, {
37 'url': 'http://player.r7.com/video/i/54e7050b0cf2ff57e0279389?play=true&video=http://vsh.r7.com/54e7050b0cf2ff57e0279389/ER7_RE_BG_MORTE_JOVENS_570kbps_2015-02-2009f17818-cc82-4c8f-86dc-89a66934e633-ATOS_copy.mp4&linkCallback=http://videos.r7.com/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-/idmedia/54e7050b0cf2ff57e0279389.html&thumbnail=http://vtb.r7.com/ER7_RE_BG_MORTE_JOVENS_570kbps_2015-02-2009f17818-cc82-4c8f-86dc-89a66934e633-thumb.jpg&idCategory=192&share=true&layout=full&full=true',
38 'only_matching': True,
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
44 video = self._download_json(
45 f'http://player-api.r7.com/video/i/{video_id}', video_id)
47 title = video['title']
49 formats = []
50 media_url_hls = video.get('media_url_hls')
51 if media_url_hls:
52 formats.extend(self._extract_m3u8_formats(
53 media_url_hls, video_id, 'mp4', entry_protocol='m3u8_native',
54 m3u8_id='hls', fatal=False))
55 media_url = video.get('media_url')
56 if media_url:
57 f = {
58 'url': media_url,
59 'format_id': 'http',
61 # m3u8 format always matches the http format, let's copy metadata from
62 # one to another
63 m3u8_formats = list(filter(
64 lambda f: f.get('vcodec') != 'none', formats))
65 if len(m3u8_formats) == 1:
66 f_copy = m3u8_formats[0].copy()
67 f_copy.update(f)
68 f_copy['protocol'] = 'http'
69 f = f_copy
70 formats.append(f)
72 description = video.get('description')
73 thumbnail = video.get('thumb')
74 duration = int_or_none(video.get('media_duration'))
75 like_count = int_or_none(video.get('likes'))
76 view_count = int_or_none(video.get('views'))
78 return {
79 'id': video_id,
80 'title': title,
81 'description': description,
82 'thumbnail': thumbnail,
83 'duration': duration,
84 'like_count': like_count,
85 'view_count': view_count,
86 'formats': formats,
90 class R7ArticleIE(InfoExtractor):
91 _WORKING = False
92 _ENABLED = None # XXX: pass through to GenericIE
93 _VALID_URL = r'https?://(?:[a-zA-Z]+)\.r7\.com/(?:[^/]+/)+[^/?#&]+-(?P<id>\d+)'
94 _TEST = {
95 'url': 'http://tv.r7.com/record-play/balanco-geral/videos/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-16102015',
96 'only_matching': True,
99 @classmethod
100 def suitable(cls, url):
101 return False if R7IE.suitable(url) else super().suitable(url)
103 def _real_extract(self, url):
104 display_id = self._match_id(url)
106 webpage = self._download_webpage(url, display_id)
108 video_id = self._search_regex(
109 r'<div[^>]+(?:id=["\']player-|class=["\']embed["\'][^>]+id=["\'])([\da-f]{24})',
110 webpage, 'video id')
112 return self.url_result(f'http://player.r7.com/video/i/{video_id}', R7IE.ie_key())