mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 14:27:53 +00:00
refactor and fix
This commit is contained in:
parent
6abc344f22
commit
3ee378c099
@ -3,16 +3,13 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_b64decode,
|
|
||||||
compat_str,
|
compat_str,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
url_or_none,
|
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
urljoin,
|
urljoin,
|
||||||
)
|
)
|
||||||
@ -105,39 +102,35 @@ class PlatziIE(PlatziBaseIE):
|
|||||||
|
|
||||||
webpage = self._download_webpage(url, lecture_id)
|
webpage = self._download_webpage(url, lecture_id)
|
||||||
data_preloaded_state = self._parse_json(
|
data_preloaded_state = self._parse_json(
|
||||||
self._search_regex((r'window.__PRELOADED_STATE__ = (.*)\<\/script'), webpage, 'client data'),
|
self._search_regex(
|
||||||
|
(r'window\s*.\s*__PRELOADED_STATE__\s*=\s*({.*?});?\s*</script'), webpage, 'client data'),
|
||||||
lecture_id)
|
lecture_id)
|
||||||
|
|
||||||
# desc = data_preloaded_state['videoPlayer']['courseDescription']
|
video_player = try_get(data_preloaded_state, lambda x: x['videoPlayer'], dict)
|
||||||
title = data_preloaded_state['videoPlayer']['name']
|
title = video_player.get('name', '')
|
||||||
duration = data_preloaded_state['videoPlayer']['duration']
|
duration = video_player.get('duration', '')
|
||||||
servers = data_preloaded_state['videoPlayer']['video']['servers']
|
servers = video_player.get('video', '').get('servers', {})
|
||||||
formats = []
|
formats = []
|
||||||
for server in servers.keys():
|
for server in servers.keys():
|
||||||
for format_id in ('hls', 'dash'):
|
server_json = servers.get(server, {})
|
||||||
server_json = servers[server]
|
if 'hls' in server_json.keys():
|
||||||
if 'hls' in server_json.keys():
|
formats.extend(self._extract_m3u8_formats(
|
||||||
formats.extend(self._extract_m3u8_formats(
|
server_json['hls'], lecture_id, 'mp4',
|
||||||
server_json['hls'], lecture_id, 'mp4',
|
entry_protocol='m3u8_native', m3u8_id='hls',
|
||||||
entry_protocol='m3u8_native', m3u8_id=format_id,
|
note='Downloading %s m3u8 information' % server_json.get('id', ''),
|
||||||
note='Downloading %s m3u8 information' % server_json['id'],
|
fatal=False))
|
||||||
fatal=False))
|
elif 'dash' in server_json.keys():
|
||||||
elif 'dash' in server_json.keys():
|
formats.extend(self._extract_mpd_formats(
|
||||||
formats.extend(self._extract_mpd_formats(
|
server_json['dash'], lecture_id, mpd_id='dash',
|
||||||
server_json['dash'], lecture_id, mpd_id=format_id,
|
note='Downloading %s MPD manifest' % server_json.get('id', ''),
|
||||||
note='Downloading %s MPD manifest' % server_json['id'],
|
fatal=False))
|
||||||
fatal=False))
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
# content = str_or_none(data['videoPlayer']['content'])
|
|
||||||
# description = (clean_html(compat_b64decode(content).decode('utf-8'))
|
|
||||||
# if content else None)
|
|
||||||
duration = int_or_none(duration, invscale=60)
|
duration = int_or_none(duration, invscale=60)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': lecture_id,
|
'id': lecture_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': '',
|
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user