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