mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 02:42:30 +00:00
[canvas] Improve (Closes #7145)
This commit is contained in:
parent
be2d40a58a
commit
4e2743abd9
@ -1,80 +1,65 @@
|
|||||||
# coding: utf-8
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
|
||||||
import urlparse
|
|
||||||
|
|
||||||
from youtube_dl import utils
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..utils import float_or_none
|
||||||
|
|
||||||
|
|
||||||
class CanvasIE(InfoExtractor):
|
class CanvasIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?:https?://)?(?:www\.)?canvas\.be/video/(?P<id>.+)'
|
_VALID_URL = r'https?://(?:www\.)?canvas\.be/video/(?:[^/]+/)*(?P<id>[^/?#&]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
|
'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
|
||||||
'md5': 'ea838375a547ac787d4064d8c7860a6c',
|
'md5': 'ea838375a547ac787d4064d8c7860a6c',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
|
'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
|
||||||
'title': 'De afspraak veilt voor de Warmste Week',
|
'display_id': 'de-afspraak-veilt-voor-de-warmste-week',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'duration': 49,
|
'title': 'De afspraak veilt voor de Warmste Week',
|
||||||
|
'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6',
|
||||||
|
'thumbnail': 're:^https?://.*\.jpg$',
|
||||||
|
'duration': 49.02,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
title = self._search_regex(
|
title = self._search_regex(
|
||||||
r'<h1 class="video__body__header__title">(.+?)</h1>', webpage,
|
r'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>',
|
||||||
'title')
|
webpage, 'title', default=None) or self._og_search_title(webpage)
|
||||||
data_video = self._html_search_regex(
|
|
||||||
r'data-video=(["\'])(?P<id>.+?)\1', webpage, 'data-video', group='id')
|
video_id = self._html_search_regex(
|
||||||
json_url = 'https://mediazone.vrt.be/api/v1/canvas/assets/' + data_video
|
r'data-video=(["\'])(?P<id>.+?)\1', webpage, 'video id', group='id')
|
||||||
data = self._download_json(json_url, video_id)
|
|
||||||
|
data = self._download_json(
|
||||||
|
'https://mediazone.vrt.be/api/v1/canvas/assets/%s' % video_id, display_id)
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for target in data['targetUrls']:
|
for target in data['targetUrls']:
|
||||||
if 'type' and 'url' in target:
|
format_url, format_type = target.get('url'), target.get('type')
|
||||||
extension = utils.determine_ext(target['url'])
|
if not format_url or not format_type:
|
||||||
if target['type'] == 'PROGRESSIVE_DOWNLOAD':
|
continue
|
||||||
formats.append({
|
if format_type == 'HLS':
|
||||||
'format_id': extension,
|
formats.extend(self._extract_m3u8_formats(
|
||||||
'url': target['url'],
|
format_url, display_id, entry_protocol='m3u8_native',
|
||||||
'protocol': 'http',
|
ext='mp4', preference=0, fatal=False, m3u8_id=format_type))
|
||||||
})
|
elif format_type == 'HDS':
|
||||||
elif target['type'] == 'HLS':
|
formats.extend(self._extract_f4m_formats(
|
||||||
formats.extend(self._extract_m3u8_formats(
|
format_url, display_id, f4m_id=format_type, fatal=False))
|
||||||
target['url'], video_id, entry_protocol='m3u8_native',
|
else:
|
||||||
ext='mp4',
|
formats.append({
|
||||||
preference=0,
|
'format_id': format_type,
|
||||||
fatal=False,
|
'url': format_url,
|
||||||
m3u8_id='hls'))
|
})
|
||||||
elif target['type'] == 'HDS':
|
|
||||||
formats.append({
|
|
||||||
'format_id': extension,
|
|
||||||
'url': target['url'],
|
|
||||||
'protocol': 'HDS',
|
|
||||||
})
|
|
||||||
elif target['type'] == 'RTMP':
|
|
||||||
formats.append({
|
|
||||||
'format_id': extension,
|
|
||||||
'url': target['url'],
|
|
||||||
'protocol': 'rtmp',
|
|
||||||
})
|
|
||||||
elif target['type'] == 'RTSP':
|
|
||||||
formats.append({
|
|
||||||
'format_id': extension,
|
|
||||||
'url': target['url'],
|
|
||||||
'protocol': 'rtsp',
|
|
||||||
})
|
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
duration = utils.int_or_none(data.get('duration')) / 1000
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
'display_id': display_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
'description': self._og_search_description(webpage),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'duration': duration,
|
'duration': float_or_none(data.get('duration'), 1000),
|
||||||
|
'thumbnail': data.get('posterImageUrl'),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user