2016-05-19 11:59:59 -07:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
2016-06-26 07:10:05 -07:00
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..compat import compat_str
|
2016-05-19 11:59:59 -07:00
|
|
|
|
from ..utils import (
|
2016-06-26 07:10:05 -07:00
|
|
|
|
determine_ext,
|
|
|
|
|
ExtractorError,
|
2016-05-19 11:59:59 -07:00
|
|
|
|
int_or_none,
|
2016-06-26 07:10:05 -07:00
|
|
|
|
unescapeHTML,
|
2016-05-19 11:59:59 -07:00
|
|
|
|
)
|
|
|
|
|
|
2016-06-26 07:10:05 -07:00
|
|
|
|
|
2016-05-19 11:59:59 -07:00
|
|
|
|
class MSNIE(InfoExtractor):
|
2019-11-29 08:31:17 -08:00
|
|
|
|
_VALID_URL = r'https?://(?:(?:www|preview)\.)?msn\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/[a-z]{2}-(?P<id>[\da-zA-Z]+)'
|
2016-05-19 11:59:59 -07:00
|
|
|
|
_TESTS = [{
|
2019-11-29 08:31:17 -08:00
|
|
|
|
'url': 'https://www.msn.com/en-in/money/video/7-ways-to-get-rid-of-chest-congestion/vi-BBPxU6d',
|
|
|
|
|
'md5': '087548191d273c5c55d05028f8d2cbcd',
|
2016-05-19 11:59:59 -07:00
|
|
|
|
'info_dict': {
|
2019-11-29 08:31:17 -08:00
|
|
|
|
'id': 'BBPxU6d',
|
|
|
|
|
'display_id': '7-ways-to-get-rid-of-chest-congestion',
|
2016-06-26 07:10:05 -07:00
|
|
|
|
'ext': 'mp4',
|
2019-11-29 08:31:17 -08:00
|
|
|
|
'title': 'Seven ways to get rid of chest congestion',
|
|
|
|
|
'description': '7 Ways to Get Rid of Chest Congestion',
|
|
|
|
|
'duration': 88,
|
|
|
|
|
'uploader': 'Health',
|
|
|
|
|
'uploader_id': 'BBPrMqa',
|
2016-05-19 11:59:59 -07:00
|
|
|
|
},
|
2019-11-29 08:31:17 -08:00
|
|
|
|
}, {
|
|
|
|
|
# Article, multiple Dailymotion Embeds
|
|
|
|
|
'url': 'https://www.msn.com/en-in/money/sports/hottest-football-wags-greatest-footballers-turned-managers-and-more/ar-BBpc7Nl',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'BBpc7Nl',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 4,
|
2016-05-19 11:59:59 -07:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.msn.com/en-ae/news/offbeat/meet-the-nine-year-old-self-made-millionaire/ar-BBt6ZKf',
|
2016-06-26 07:10:05 -07:00
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.msn.com/en-ae/video/watch/obama-a-lot-of-people-will-be-disappointed/vi-AAhxUMH',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
# geo restricted
|
|
|
|
|
'url': 'http://www.msn.com/en-ae/foodanddrink/joinourtable/the-first-fart-makes-you-laugh-the-last-fart-makes-you-cry/vp-AAhzIBU',
|
|
|
|
|
'only_matching': True,
|
2016-06-26 08:02:46 -07:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://www.msn.com/en-ae/entertainment/bollywood/watch-how-salman-khan-reacted-when-asked-if-he-would-apologize-for-his-‘raped-woman’-comment/vi-AAhvzW6',
|
|
|
|
|
'only_matching': True,
|
2019-11-04 13:21:00 -08:00
|
|
|
|
}, {
|
|
|
|
|
# Vidible(AOL) Embed
|
2019-11-29 08:31:17 -08:00
|
|
|
|
'url': 'https://www.msn.com/en-us/money/other/jupiter-is-about-to-come-so-close-you-can-see-its-moons-with-binoculars/vi-AACqsHR',
|
2019-11-04 13:21:00 -08:00
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
# Dailymotion Embed
|
|
|
|
|
'url': 'https://www.msn.com/es-ve/entretenimiento/watch/winston-salem-paire-refait-des-siennes-en-perdant-sa-raquette-au-service/vp-AAG704L',
|
|
|
|
|
'only_matching': True,
|
2019-11-29 08:31:17 -08:00
|
|
|
|
}, {
|
|
|
|
|
# YouTube Embed
|
|
|
|
|
'url': 'https://www.msn.com/en-in/money/news/meet-vikram-%E2%80%94-chandrayaan-2s-lander/vi-AAGUr0v',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
# NBCSports Embed
|
|
|
|
|
'url': 'https://www.msn.com/en-us/money/football_nfl/week-13-preview-redskins-vs-panthers/vi-BBXsCDb',
|
|
|
|
|
'only_matching': True,
|
2016-05-19 11:59:59 -07:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2019-11-29 08:31:17 -08:00
|
|
|
|
display_id, page_id = re.match(self._VALID_URL, url).groups()
|
2016-05-19 11:59:59 -07:00
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, display_id)
|
|
|
|
|
|
2019-11-29 08:31:17 -08:00
|
|
|
|
entries = []
|
|
|
|
|
for _, metadata in re.findall(r'data-metadata\s*=\s*(["\'])(?P<data>.+?)\1', webpage):
|
|
|
|
|
video = self._parse_json(unescapeHTML(metadata), display_id)
|
2016-06-26 07:10:05 -07:00
|
|
|
|
|
2019-11-04 13:21:00 -08:00
|
|
|
|
provider_id = video.get('providerId')
|
2019-11-29 08:31:17 -08:00
|
|
|
|
player_name = video.get('playerName')
|
|
|
|
|
if player_name and provider_id:
|
|
|
|
|
entry = None
|
2019-11-04 13:21:00 -08:00
|
|
|
|
if player_name == 'AOL':
|
2019-11-29 08:31:17 -08:00
|
|
|
|
if provider_id.startswith('http'):
|
|
|
|
|
provider_id = self._search_regex(
|
|
|
|
|
r'https?://delivery\.vidible\.tv/video/redirect/([0-9a-f]{24})',
|
|
|
|
|
provider_id, 'vidible id')
|
|
|
|
|
entry = self.url_result(
|
2019-11-04 13:21:00 -08:00
|
|
|
|
'aol-video:' + provider_id, 'Aol', provider_id)
|
|
|
|
|
elif player_name == 'Dailymotion':
|
2019-11-29 08:31:17 -08:00
|
|
|
|
entry = self.url_result(
|
2019-11-04 13:21:00 -08:00
|
|
|
|
'https://www.dailymotion.com/video/' + provider_id,
|
|
|
|
|
'Dailymotion', provider_id)
|
2019-11-29 08:31:17 -08:00
|
|
|
|
elif player_name == 'YouTube':
|
|
|
|
|
entry = self.url_result(
|
|
|
|
|
provider_id, 'Youtube', provider_id)
|
|
|
|
|
elif player_name == 'NBCSports':
|
|
|
|
|
entry = self.url_result(
|
|
|
|
|
'http://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/' + provider_id,
|
|
|
|
|
'NBCSportsVPlayer', provider_id)
|
|
|
|
|
if entry:
|
|
|
|
|
entries.append(entry)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
video_id = video['uuid']
|
|
|
|
|
title = video['title']
|
|
|
|
|
|
|
|
|
|
formats = []
|
|
|
|
|
for file_ in video.get('videoFiles', []):
|
|
|
|
|
format_url = file_.get('url')
|
|
|
|
|
if not format_url:
|
|
|
|
|
continue
|
|
|
|
|
if 'format=m3u8-aapl' in format_url:
|
|
|
|
|
# m3u8_native should not be used here until
|
|
|
|
|
# https://github.com/ytdl-org/youtube-dl/issues/9913 is fixed
|
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
|
format_url, display_id, 'mp4',
|
|
|
|
|
m3u8_id='hls', fatal=False))
|
|
|
|
|
elif 'format=mpd-time-csf' in format_url:
|
|
|
|
|
formats.extend(self._extract_mpd_formats(
|
|
|
|
|
format_url, display_id, 'dash', fatal=False))
|
|
|
|
|
elif '.ism' in format_url:
|
|
|
|
|
if format_url.endswith('.ism'):
|
|
|
|
|
format_url += '/manifest'
|
|
|
|
|
formats.extend(self._extract_ism_formats(
|
|
|
|
|
format_url, display_id, 'mss', fatal=False))
|
|
|
|
|
else:
|
|
|
|
|
format_id = file_.get('formatCode')
|
|
|
|
|
formats.append({
|
|
|
|
|
'url': format_url,
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'format_id': format_id,
|
|
|
|
|
'width': int_or_none(file_.get('width')),
|
|
|
|
|
'height': int_or_none(file_.get('height')),
|
|
|
|
|
'vbr': int_or_none(self._search_regex(r'_(\d+)\.mp4', format_url, 'vbr', default=None)),
|
|
|
|
|
'preference': 1 if format_id == '1001' else None,
|
|
|
|
|
})
|
|
|
|
|
self._sort_formats(formats)
|
2019-11-04 13:21:00 -08:00
|
|
|
|
|
2019-11-29 08:31:17 -08:00
|
|
|
|
subtitles = {}
|
|
|
|
|
for file_ in video.get('files', []):
|
|
|
|
|
format_url = file_.get('url')
|
|
|
|
|
format_code = file_.get('formatCode')
|
|
|
|
|
if not format_url or not format_code:
|
|
|
|
|
continue
|
|
|
|
|
if compat_str(format_code) == '3100':
|
|
|
|
|
subtitles.setdefault(file_.get('culture', 'en'), []).append({
|
|
|
|
|
'ext': determine_ext(format_url, 'ttml'),
|
|
|
|
|
'url': format_url,
|
|
|
|
|
})
|
2016-05-19 11:59:59 -07:00
|
|
|
|
|
2019-11-29 08:31:17 -08:00
|
|
|
|
entries.append({
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'display_id': display_id,
|
|
|
|
|
'title': title,
|
|
|
|
|
'description': video.get('description'),
|
|
|
|
|
'thumbnail': video.get('headlineImage', {}).get('url'),
|
|
|
|
|
'duration': int_or_none(video.get('durationSecs')),
|
|
|
|
|
'uploader': video.get('sourceFriendly'),
|
|
|
|
|
'uploader_id': video.get('providerId'),
|
|
|
|
|
'creator': video.get('creator'),
|
|
|
|
|
'subtitles': subtitles,
|
|
|
|
|
'formats': formats,
|
|
|
|
|
})
|
2016-05-19 11:59:59 -07:00
|
|
|
|
|
2019-11-29 08:31:17 -08:00
|
|
|
|
if not entries:
|
|
|
|
|
error = unescapeHTML(self._search_regex(
|
|
|
|
|
r'data-error=(["\'])(?P<error>.+?)\1',
|
|
|
|
|
webpage, 'error', group='error'))
|
|
|
|
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
|
2016-05-19 11:59:59 -07:00
|
|
|
|
|
2019-11-29 08:31:17 -08:00
|
|
|
|
return self.playlist_result(entries, page_id)
|