mirror of https://github.com/yt-dlp/yt-dlp
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.0 KiB
Python
82 lines
3.0 KiB
Python
7 years ago
|
import re
|
||
|
|
||
9 years ago
|
from .common import InfoExtractor
|
||
8 years ago
|
from ..compat import compat_str
|
||
9 years ago
|
from ..utils import (
|
||
|
int_or_none,
|
||
|
determine_protocol,
|
||
8 years ago
|
try_get,
|
||
8 years ago
|
unescapeHTML,
|
||
9 years ago
|
)
|
||
|
|
||
|
|
||
|
class DailyMailIE(InfoExtractor):
|
||
7 years ago
|
_VALID_URL = r'https?://(?:www\.)?dailymail\.co\.uk/(?:video/[^/]+/video-|embed/video/)(?P<id>[0-9]+)'
|
||
|
_TESTS = [{
|
||
8 years ago
|
'url': 'http://www.dailymail.co.uk/video/tvshowbiz/video-1295863/The-Mountain-appears-sparkling-water-ad-Heavy-Bubbles.html',
|
||
|
'md5': 'f6129624562251f628296c3a9ffde124',
|
||
9 years ago
|
'info_dict': {
|
||
8 years ago
|
'id': '1295863',
|
||
9 years ago
|
'ext': 'mp4',
|
||
8 years ago
|
'title': 'The Mountain appears in sparkling water ad for \'Heavy Bubbles\'',
|
||
|
'description': 'md5:a93d74b6da172dd5dc4d973e0b766a84',
|
||
9 years ago
|
}
|
||
7 years ago
|
}, {
|
||
|
'url': 'http://www.dailymail.co.uk/embed/video/1295863.html',
|
||
|
'only_matching': True,
|
||
|
}]
|
||
|
|
||
|
@staticmethod
|
||
|
def _extract_urls(webpage):
|
||
|
return re.findall(
|
||
|
r'<iframe\b[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?dailymail\.co\.uk/embed/video/\d+\.html)',
|
||
|
webpage)
|
||
9 years ago
|
|
||
|
def _real_extract(self, url):
|
||
|
video_id = self._match_id(url)
|
||
|
webpage = self._download_webpage(url, video_id)
|
||
|
video_data = self._parse_json(self._search_regex(
|
||
|
r"data-opts='({.+?})'", webpage, 'video data'), video_id)
|
||
8 years ago
|
title = unescapeHTML(video_data['title'])
|
||
8 years ago
|
|
||
|
sources_url = (try_get(
|
||
|
video_data,
|
||
|
(lambda x: x['plugins']['sources']['url'],
|
||
6 years ago
|
lambda x: x['sources']['url']), compat_str)
|
||
|
or 'http://www.dailymail.co.uk/api/player/%s/video-sources.json' % video_id)
|
||
8 years ago
|
|
||
|
video_sources = self._download_json(sources_url, video_id)
|
||
6 years ago
|
body = video_sources.get('body')
|
||
|
if body:
|
||
|
video_sources = body
|
||
9 years ago
|
|
||
|
formats = []
|
||
|
for rendition in video_sources['renditions']:
|
||
|
rendition_url = rendition.get('url')
|
||
|
if not rendition_url:
|
||
|
continue
|
||
|
tbr = int_or_none(rendition.get('encodingRate'), 1000)
|
||
|
container = rendition.get('videoContainer')
|
||
|
is_hls = container == 'M2TS'
|
||
|
protocol = 'm3u8_native' if is_hls else determine_protocol({'url': rendition_url})
|
||
|
formats.append({
|
||
|
'format_id': ('hls' if is_hls else protocol) + ('-%d' % tbr if tbr else ''),
|
||
|
'url': rendition_url,
|
||
|
'width': int_or_none(rendition.get('frameWidth')),
|
||
|
'height': int_or_none(rendition.get('frameHeight')),
|
||
|
'tbr': tbr,
|
||
|
'vcodec': rendition.get('videoCodec'),
|
||
|
'container': container,
|
||
|
'protocol': protocol,
|
||
|
'ext': 'mp4' if is_hls else None,
|
||
|
})
|
||
|
self._sort_formats(formats)
|
||
|
|
||
|
return {
|
||
|
'id': video_id,
|
||
|
'title': title,
|
||
8 years ago
|
'description': unescapeHTML(video_data.get('descr')),
|
||
9 years ago
|
'thumbnail': video_data.get('poster') or video_data.get('thumbnail'),
|
||
|
'formats': formats,
|
||
|
}
|