]>
Commit | Line | Data |
---|---|---|
add96eb9 | 1 | import urllib.parse |
2 | ||
4e62d26a RA |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
5 | clean_html, | |
6 | int_or_none, | |
7 | parse_duration, | |
ce7db64b RA |
8 | parse_iso8601, |
9 | qualities, | |
4e62d26a | 10 | update_url_query, |
4e62d26a RA |
11 | ) |
12 | ||
13 | ||
14 | class UOLIE(InfoExtractor): | |
15 | IE_NAME = 'uol.com.br' | |
16 | _VALID_URL = r'https?://(?:.+?\.)?uol\.com\.br/.*?(?:(?:mediaId|v)=|view/(?:[a-z0-9]+/)?|video(?:=|/(?:\d{4}/\d{2}/\d{2}/)?))(?P<id>\d+|[\w-]+-[A-Z0-9]+)' | |
17 | _TESTS = [{ | |
18 | 'url': 'http://player.mais.uol.com.br/player_video_v3.swf?mediaId=15951931', | |
ce7db64b | 19 | 'md5': '4f1e26683979715ff64e4e29099cf020', |
4e62d26a RA |
20 | 'info_dict': { |
21 | 'id': '15951931', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Miss simpatia é encontrada morta', | |
24 | 'description': 'md5:3f8c11a0c0556d66daf7e5b45ef823b2', | |
ce7db64b RA |
25 | 'timestamp': 1470421860, |
26 | 'upload_date': '20160805', | |
add96eb9 | 27 | }, |
4e62d26a RA |
28 | }, { |
29 | 'url': 'http://tvuol.uol.com.br/video/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326', | |
ce7db64b | 30 | 'md5': '2850a0e8dfa0a7307e04a96c5bdc5bc2', |
4e62d26a RA |
31 | 'info_dict': { |
32 | 'id': '15954259', | |
33 | 'ext': 'mp4', | |
34 | 'title': 'Incêndio destrói uma das maiores casas noturnas de Londres', | |
35 | 'description': 'Em Londres, um incêndio destruiu uma das maiores boates da cidade. Não há informações sobre vítimas.', | |
ce7db64b RA |
36 | 'timestamp': 1470674520, |
37 | 'upload_date': '20160808', | |
add96eb9 | 38 | }, |
4e62d26a RA |
39 | }, { |
40 | 'url': 'http://mais.uol.com.br/static/uolplayer/index.html?mediaId=15951931', | |
41 | 'only_matching': True, | |
42 | }, { | |
43 | 'url': 'http://mais.uol.com.br/view/15954259', | |
44 | 'only_matching': True, | |
45 | }, { | |
46 | 'url': 'http://noticias.band.uol.com.br/brasilurgente/video/2016/08/05/15951931/miss-simpatia-e-encontrada-morta.html', | |
47 | 'only_matching': True, | |
48 | }, { | |
49 | 'url': 'http://videos.band.uol.com.br/programa.asp?e=noticias&pr=brasil-urgente&v=15951931&t=Policia-desmonte-base-do-PCC-na-Cracolandia', | |
50 | 'only_matching': True, | |
51 | }, { | |
52 | 'url': 'http://mais.uol.com.br/view/cphaa0gl2x8r/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326', | |
53 | 'only_matching': True, | |
54 | }, { | |
55 | 'url': 'http://noticias.uol.com.br//videos/assistir.htm?video=rafaela-silva-inspira-criancas-no-judo-04024D983968D4C95326', | |
56 | 'only_matching': True, | |
57 | }, { | |
58 | 'url': 'http://mais.uol.com.br/view/e0qbgxid79uv/15275470', | |
59 | 'only_matching': True, | |
60 | }] | |
61 | ||
4e62d26a RA |
62 | def _real_extract(self, url): |
63 | video_id = self._match_id(url) | |
eb3f008c | 64 | |
4e62d26a | 65 | video_data = self._download_json( |
ce7db64b RA |
66 | # https://api.mais.uol.com.br/apiuol/v4/player/data/[MEDIA_ID] |
67 | 'https://api.mais.uol.com.br/apiuol/v3/media/detail/' + video_id, | |
68 | video_id)['item'] | |
add96eb9 | 69 | media_id = str(video_data['mediaId']) |
4e62d26a | 70 | title = video_data['title'] |
ce7db64b | 71 | ver = video_data.get('revision', 2) |
4e62d26a | 72 | |
ce7db64b | 73 | uol_formats = self._download_json( |
add96eb9 | 74 | f'https://croupier.mais.uol.com.br/v3/formats/{media_id}/jsonp', |
ce7db64b RA |
75 | media_id) |
76 | quality = qualities(['mobile', 'WEBM', '360p', '720p', '1080p']) | |
4e62d26a | 77 | formats = [] |
ce7db64b RA |
78 | for format_id, f in uol_formats.items(): |
79 | if not isinstance(f, dict): | |
80 | continue | |
4e62d26a RA |
81 | f_url = f.get('url') or f.get('secureUrl') |
82 | if not f_url: | |
83 | continue | |
ce7db64b RA |
84 | query = { |
85 | 'ver': ver, | |
86 | 'r': 'http://mais.uol.com.br', | |
87 | } | |
88 | for k in ('token', 'sign'): | |
89 | v = f.get(k) | |
90 | if v: | |
91 | query[k] = v | |
13e17cd2 | 92 | f_url = update_url_query(f_url, query) |
ce7db64b RA |
93 | if format_id == 'HLS': |
94 | m3u8_formats = self._extract_m3u8_formats( | |
95 | f_url, media_id, 'mp4', 'm3u8_native', | |
96 | m3u8_id='hls', fatal=False) | |
add96eb9 | 97 | encoded_query = urllib.parse.urlencode(query) |
ce7db64b RA |
98 | for m3u8_f in m3u8_formats: |
99 | m3u8_f['extra_param_to_segment_url'] = encoded_query | |
100 | m3u8_f['url'] = update_url_query(m3u8_f['url'], query) | |
101 | formats.extend(m3u8_formats) | |
13e17cd2 | 102 | continue |
ce7db64b | 103 | formats.append({ |
4e62d26a | 104 | 'format_id': format_id, |
13e17cd2 | 105 | 'url': f_url, |
ce7db64b | 106 | 'quality': quality(format_id), |
ce7db64b | 107 | }) |
4e62d26a RA |
108 | |
109 | tags = [] | |
110 | for tag in video_data.get('tags', []): | |
111 | tag_description = tag.get('description') | |
112 | if not tag_description: | |
113 | continue | |
114 | tags.append(tag_description) | |
115 | ||
ce7db64b RA |
116 | thumbnails = [] |
117 | for q in ('Small', 'Medium', 'Wmedium', 'Large', 'Wlarge', 'Xlarge'): | |
118 | q_url = video_data.get('thumb' + q) | |
119 | if not q_url: | |
120 | continue | |
121 | thumbnails.append({ | |
122 | 'id': q, | |
123 | 'url': q_url, | |
124 | }) | |
125 | ||
4e62d26a | 126 | return { |
eb3f008c | 127 | 'id': media_id, |
4e62d26a | 128 | 'title': title, |
ce7db64b RA |
129 | 'description': clean_html(video_data.get('description')), |
130 | 'thumbnails': thumbnails, | |
131 | 'duration': parse_duration(video_data.get('duration')), | |
4e62d26a RA |
132 | 'tags': tags, |
133 | 'formats': formats, | |
ce7db64b RA |
134 | 'timestamp': parse_iso8601(video_data.get('publishDate'), ' '), |
135 | 'view_count': int_or_none(video_data.get('viewsQtty')), | |
4e62d26a | 136 | } |