[history] fix signature and media url extraction(fixes #8240)
[youtube-dl] / youtube_dl / extractor / history.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import smuggle_url
5 from ..compat import compat_urllib_parse
6
7
8 class HistoryIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?history\.com/(?:[^/]+/)+(?P<id>[^/]+?)(?:$|[?#])'
10
11     _TESTS = [{
12         'url': 'http://www.history.com/topics/valentines-day/history-of-valentines-day/videos/bet-you-didnt-know-valentines-day?m=528e394da93ae&s=undefined&f=1&free=false',
13         'md5': '6fe632d033c92aa10b8d4a9be047a7c5',
14         'info_dict': {
15             'id': 'bLx5Dv5Aka1G',
16             'ext': 'mp4',
17             'title': "Bet You Didn't Know: Valentine's Day",
18             'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
19         },
20         'add_ie': ['ThePlatform'],
21     }]
22
23     _VIDEO_URL_RE = [
24         r"media_url\s*=\s*'[^']'",
25         r'data-mediaurl="([^"]+)"'
26     ]
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30
31         webpage = self._download_webpage(url, video_id)
32
33         media_url = self._search_regex(self._VIDEO_URL_RE, webpage, 'video url')
34
35         pdk_signature = webpage = self._download_webpage(
36             'https://signature.video.aetndigital.com/?' +
37             compat_urllib_parse.urlencode({'url': media_url}), video_id)
38
39         return self.url_result(smuggle_url(
40             media_url + '?mbr=true&format=smil&sig=' + pdk_signature, {'force_smil_url': True}))