mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 02:42:30 +00:00
parent
0001fcb586
commit
b89378a69a
@ -9,15 +9,14 @@
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_HTTPError,
|
|
||||||
compat_str,
|
compat_str,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
|
||||||
orderedSet,
|
orderedSet,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
|
try_get,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -26,18 +25,19 @@ class GloboIE(InfoExtractor):
|
|||||||
_NETRC_MACHINE = 'globo'
|
_NETRC_MACHINE = 'globo'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://g1.globo.com/carros/autoesporte/videos/t/exclusivos-do-g1/v/mercedes-benz-gla-passa-por-teste-de-colisao-na-europa/3607726/',
|
'url': 'http://g1.globo.com/carros/autoesporte/videos/t/exclusivos-do-g1/v/mercedes-benz-gla-passa-por-teste-de-colisao-na-europa/3607726/',
|
||||||
'md5': 'b3ccc801f75cd04a914d51dadb83a78d',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '3607726',
|
'id': '3607726',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Mercedes-Benz GLA passa por teste de colisão na Europa',
|
'title': 'Mercedes-Benz GLA passa por teste de colisão na Europa',
|
||||||
'duration': 103.204,
|
'duration': 103.204,
|
||||||
'uploader': 'Globo.com',
|
'uploader': 'G1',
|
||||||
'uploader_id': '265',
|
'uploader_id': '2015',
|
||||||
|
},
|
||||||
|
'params': {
|
||||||
|
'skip_download': True,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://globoplay.globo.com/v/4581987/',
|
'url': 'http://globoplay.globo.com/v/4581987/',
|
||||||
'md5': 'f36a1ecd6a50da1577eee6dd17f67eff',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '4581987',
|
'id': '4581987',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@ -46,6 +46,9 @@ class GloboIE(InfoExtractor):
|
|||||||
'uploader': 'Rede Globo',
|
'uploader': 'Rede Globo',
|
||||||
'uploader_id': '196',
|
'uploader_id': '196',
|
||||||
},
|
},
|
||||||
|
'params': {
|
||||||
|
'skip_download': True,
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://canalbrasil.globo.com/programas/sangue-latino/videos/3928201.html',
|
'url': 'http://canalbrasil.globo.com/programas/sangue-latino/videos/3928201.html',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
@ -66,30 +69,6 @@ class GloboIE(InfoExtractor):
|
|||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_initialize(self):
|
|
||||||
email, password = self._get_login_info()
|
|
||||||
if email is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
glb_id = (self._download_json(
|
|
||||||
'https://login.globo.com/api/authentication', None, data=json.dumps({
|
|
||||||
'payload': {
|
|
||||||
'email': email,
|
|
||||||
'password': password,
|
|
||||||
'serviceId': 4654,
|
|
||||||
},
|
|
||||||
}).encode(), headers={
|
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
|
||||||
}) or {}).get('glbId')
|
|
||||||
if glb_id:
|
|
||||||
self._set_cookie('.globo.com', 'GLBID', glb_id)
|
|
||||||
except ExtractorError as e:
|
|
||||||
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
|
|
||||||
resp = self._parse_json(e.cause.read(), None)
|
|
||||||
raise ExtractorError(resp.get('userMessage') or resp['id'], expected=True)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
@ -102,35 +81,23 @@ def _real_extract(self, url):
|
|||||||
title = video['title']
|
title = video['title']
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
subtitles = {}
|
|
||||||
for resource in video['resources']:
|
|
||||||
resource_id = resource.get('_id')
|
|
||||||
resource_url = resource.get('url')
|
|
||||||
resource_type = resource.get('type')
|
|
||||||
if not resource_url or (resource_type == 'media' and not resource_id) or resource_type not in ('subtitle', 'media'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if resource_type == 'subtitle':
|
|
||||||
subtitles.setdefault(resource.get('language') or 'por', []).append({
|
|
||||||
'url': resource_url,
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
|
|
||||||
security = self._download_json(
|
security = self._download_json(
|
||||||
'http://security.video.globo.com/videos/%s/hash' % video_id,
|
'https://playback.video.globo.com/v1/video-session', video_id, 'Downloading security hash for %s' % video_id,
|
||||||
video_id, 'Downloading security hash for %s' % resource_id, query={
|
headers={'content-type': 'application/json'}, data=json.dumps({
|
||||||
'player': 'desktop',
|
"player_type": "desktop",
|
||||||
'version': '5.19.1',
|
"video_id": video_id,
|
||||||
'resource_id': resource_id,
|
"quality": "max",
|
||||||
})
|
"content_protection": "widevine",
|
||||||
|
"vsid": "581b986b-4c40-71f0-5a58-803e579d5fa2",
|
||||||
|
"tz": "-3.0:00"
|
||||||
|
}).encode())
|
||||||
|
|
||||||
security_hash = security.get('hash')
|
security_hash = security['source']['token']
|
||||||
if not security_hash:
|
if not security_hash:
|
||||||
message = security.get('message')
|
message = security.get('message')
|
||||||
if message:
|
if message:
|
||||||
raise ExtractorError(
|
raise ExtractorError(
|
||||||
'%s returned error: %s' % (self.IE_NAME, message), expected=True)
|
'%s returned error: %s' % (self.IE_NAME, message), expected=True)
|
||||||
continue
|
|
||||||
|
|
||||||
hash_code = security_hash[:2]
|
hash_code = security_hash[:2]
|
||||||
padding = '%010d' % random.randint(1, 10000000000)
|
padding = '%010d' % random.randint(1, 10000000000)
|
||||||
@ -148,27 +115,33 @@ def _real_extract(self, url):
|
|||||||
md5_data = (received_md5 + padded_sign_time + '0xAC10FD').encode()
|
md5_data = (received_md5 + padded_sign_time + '0xAC10FD').encode()
|
||||||
signed_md5 = base64.urlsafe_b64encode(hashlib.md5(md5_data).digest()).decode().strip('=')
|
signed_md5 = base64.urlsafe_b64encode(hashlib.md5(md5_data).digest()).decode().strip('=')
|
||||||
signed_hash = hash_prefix + padded_sign_time + signed_md5
|
signed_hash = hash_prefix + padded_sign_time + signed_md5
|
||||||
signed_url = '%s?h=%s&k=html5&a=%s&u=%s' % (resource_url, signed_hash, 'F' if video.get('subscriber_only') else 'A', security.get('user') or '')
|
source = security['source']['url_parts']
|
||||||
|
resource_url = source['scheme'] + '://' + source['domain'] + source['path']
|
||||||
|
signed_url = '%s?h=%s&k=html5&a=%s' % (resource_url, signed_hash, 'F' if video.get('subscriber_only') else 'A')
|
||||||
|
|
||||||
if resource_id.endswith('m3u8') or resource_url.endswith('.m3u8'):
|
|
||||||
formats.extend(self._extract_m3u8_formats(
|
formats.extend(self._extract_m3u8_formats(
|
||||||
signed_url, resource_id, 'mp4', entry_protocol='m3u8_native',
|
signed_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
|
||||||
m3u8_id='hls', fatal=False))
|
|
||||||
elif resource_id.endswith('mpd') or resource_url.endswith('.mpd'):
|
|
||||||
formats.extend(self._extract_mpd_formats(
|
|
||||||
signed_url, resource_id, mpd_id='dash', fatal=False))
|
|
||||||
elif resource_id.endswith('manifest') or resource_url.endswith('/manifest'):
|
|
||||||
formats.extend(self._extract_ism_formats(
|
|
||||||
signed_url, resource_id, ism_id='mss', fatal=False))
|
|
||||||
else:
|
|
||||||
formats.append({
|
|
||||||
'url': signed_url,
|
|
||||||
'format_id': 'http-%s' % resource_id,
|
|
||||||
'height': int_or_none(resource.get('height')),
|
|
||||||
})
|
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
subtitles = {}
|
||||||
|
for resource in video['resources']:
|
||||||
|
if resource.get('type') == 'subtitle':
|
||||||
|
subtitles.setdefault(resource.get('language') or 'por', []).append({
|
||||||
|
'url': resource.get('url'),
|
||||||
|
})
|
||||||
|
subs = try_get(security, lambda x: x['source']['subtitles'], expected_type=dict) or {}
|
||||||
|
for sub_lang, sub_url in subs.items():
|
||||||
|
if sub_url:
|
||||||
|
subtitles.setdefault(sub_lang or 'por', []).append({
|
||||||
|
'url': sub_url,
|
||||||
|
})
|
||||||
|
subs = try_get(security, lambda x: x['source']['subtitles_webvtt'], expected_type=dict) or {}
|
||||||
|
for sub_lang, sub_url in subs.items():
|
||||||
|
if sub_url:
|
||||||
|
subtitles.setdefault(sub_lang or 'por', []).append({
|
||||||
|
'url': sub_url,
|
||||||
|
})
|
||||||
|
|
||||||
duration = float_or_none(video.get('duration'), 1000)
|
duration = float_or_none(video.get('duration'), 1000)
|
||||||
uploader = video.get('channel')
|
uploader = video.get('channel')
|
||||||
uploader_id = str_or_none(video.get('channel_id'))
|
uploader_id = str_or_none(video.get('channel_id'))
|
||||||
|
Loading…
Reference in New Issue
Block a user