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