1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-25 09:54:32 +01:00
youtube-dl/youtube_dl/extractor/uol.py

145 lines
5.4 KiB
Python
Raw Normal View History

2016-08-09 16:09:08 +02:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2020-05-05 12:19:19 +02:00
from ..compat import (
compat_str,
compat_urllib_parse_urlencode,
)
2016-08-09 16:09:08 +02:00
from ..utils import (
clean_html,
int_or_none,
parse_duration,
2020-05-05 12:19:19 +02:00
parse_iso8601,
qualities,
2016-08-09 16:09:08 +02:00
update_url_query,
)
class UOLIE(InfoExtractor):
IE_NAME = 'uol.com.br'
_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]+)'
_TESTS = [{
'url': 'http://player.mais.uol.com.br/player_video_v3.swf?mediaId=15951931',
2020-05-05 12:19:19 +02:00
'md5': '4f1e26683979715ff64e4e29099cf020',
2016-08-09 16:09:08 +02:00
'info_dict': {
'id': '15951931',
'ext': 'mp4',
'title': 'Miss simpatia é encontrada morta',
'description': 'md5:3f8c11a0c0556d66daf7e5b45ef823b2',
2020-05-05 12:19:19 +02:00
'timestamp': 1470421860,
'upload_date': '20160805',
2016-08-09 16:09:08 +02:00
}
}, {
'url': 'http://tvuol.uol.com.br/video/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326',
2020-05-05 12:19:19 +02:00
'md5': '2850a0e8dfa0a7307e04a96c5bdc5bc2',
2016-08-09 16:09:08 +02:00
'info_dict': {
'id': '15954259',
'ext': 'mp4',
'title': 'Incêndio destrói uma das maiores casas noturnas de Londres',
'description': 'Em Londres, um incêndio destruiu uma das maiores boates da cidade. Não há informações sobre vítimas.',
2020-05-05 12:19:19 +02:00
'timestamp': 1470674520,
'upload_date': '20160808',
2016-08-09 16:09:08 +02:00
}
}, {
'url': 'http://mais.uol.com.br/static/uolplayer/index.html?mediaId=15951931',
'only_matching': True,
}, {
'url': 'http://mais.uol.com.br/view/15954259',
'only_matching': True,
}, {
'url': 'http://noticias.band.uol.com.br/brasilurgente/video/2016/08/05/15951931/miss-simpatia-e-encontrada-morta.html',
'only_matching': True,
}, {
'url': 'http://videos.band.uol.com.br/programa.asp?e=noticias&pr=brasil-urgente&v=15951931&t=Policia-desmonte-base-do-PCC-na-Cracolandia',
'only_matching': True,
}, {
'url': 'http://mais.uol.com.br/view/cphaa0gl2x8r/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326',
'only_matching': True,
}, {
'url': 'http://noticias.uol.com.br//videos/assistir.htm?video=rafaela-silva-inspira-criancas-no-judo-04024D983968D4C95326',
'only_matching': True,
}, {
'url': 'http://mais.uol.com.br/view/e0qbgxid79uv/15275470',
'only_matching': True,
}]
def _real_extract(self, url):
video_id = self._match_id(url)
2017-01-18 22:49:31 +01:00
2016-08-09 16:09:08 +02:00
video_data = self._download_json(
2020-05-05 12:19:19 +02:00
# https://api.mais.uol.com.br/apiuol/v4/player/data/[MEDIA_ID]
'https://api.mais.uol.com.br/apiuol/v3/media/detail/' + video_id,
video_id)['item']
media_id = compat_str(video_data['mediaId'])
2016-08-09 16:09:08 +02:00
title = video_data['title']
2020-05-05 12:19:19 +02:00
ver = video_data.get('revision', 2)
2016-08-09 16:09:08 +02:00
2020-05-05 12:19:19 +02:00
uol_formats = self._download_json(
'https://croupier.mais.uol.com.br/v3/formats/%s/jsonp' % media_id,
media_id)
quality = qualities(['mobile', 'WEBM', '360p', '720p', '1080p'])
2016-08-09 16:09:08 +02:00
formats = []
2020-05-05 12:19:19 +02:00
for format_id, f in uol_formats.items():
if not isinstance(f, dict):
continue
2016-08-09 16:09:08 +02:00
f_url = f.get('url') or f.get('secureUrl')
if not f_url:
continue
2020-05-05 12:19:19 +02:00
query = {
'ver': ver,
'r': 'http://mais.uol.com.br',
}
for k in ('token', 'sign'):
v = f.get(k)
if v:
query[k] = v
f_url = update_url_query(f_url, query)
2020-05-05 12:19:19 +02:00
format_id = format_id
if format_id == 'HLS':
m3u8_formats = self._extract_m3u8_formats(
f_url, media_id, 'mp4', 'm3u8_native',
m3u8_id='hls', fatal=False)
encoded_query = compat_urllib_parse_urlencode(query)
for m3u8_f in m3u8_formats:
m3u8_f['extra_param_to_segment_url'] = encoded_query
m3u8_f['url'] = update_url_query(m3u8_f['url'], query)
formats.extend(m3u8_formats)
continue
2020-05-05 12:19:19 +02:00
formats.append({
2016-08-09 16:09:08 +02:00
'format_id': format_id,
'url': f_url,
2020-05-05 12:19:19 +02:00
'quality': quality(format_id),
'preference': -1,
})
self._sort_formats(formats)
2016-08-09 16:09:08 +02:00
tags = []
for tag in video_data.get('tags', []):
tag_description = tag.get('description')
if not tag_description:
continue
tags.append(tag_description)
2020-05-05 12:19:19 +02:00
thumbnails = []
for q in ('Small', 'Medium', 'Wmedium', 'Large', 'Wlarge', 'Xlarge'):
q_url = video_data.get('thumb' + q)
if not q_url:
continue
thumbnails.append({
'id': q,
'url': q_url,
})
2016-08-09 16:09:08 +02:00
return {
2017-01-18 22:49:31 +01:00
'id': media_id,
2016-08-09 16:09:08 +02:00
'title': title,
2020-05-05 12:19:19 +02:00
'description': clean_html(video_data.get('description')),
'thumbnails': thumbnails,
'duration': parse_duration(video_data.get('duration')),
2016-08-09 16:09:08 +02:00
'tags': tags,
'formats': formats,
2020-05-05 12:19:19 +02:00
'timestamp': parse_iso8601(video_data.get('publishDate'), ' '),
'view_count': int_or_none(video_data.get('viewsQtty')),
2016-08-09 16:09:08 +02:00
}