1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

[motorsport] Fix extraction and make trailing '/' optional

They directly embed a youtube video now.
This commit is contained in:
Jaime Marquínez Ferrándiz 2015-01-05 19:14:50 +01:00
parent f4bca0b348
commit 8f9529cd05

View file

@ -1,63 +1,49 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import hashlib
import json
import time
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_parse_qs, compat_urlparse,
compat_str,
)
from ..utils import (
int_or_none,
) )
class MotorsportIE(InfoExtractor): class MotorsportIE(InfoExtractor):
IE_DESC = 'motorsport.com' IE_DESC = 'motorsport.com'
_VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#])' _VALID_URL = r'http://www\.motorsport\.com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/?(?:$|[?#])'
_TEST = { _TEST = {
'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/', 'url': 'http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/',
'md5': '5592cb7c5005d9b2c163df5ac3dc04e4',
'info_dict': { 'info_dict': {
'id': '7063', 'id': '2-T3WuR-KMM',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Red Bull Racing: 2014 Rules Explained', 'title': 'Red Bull Racing: 2014 Rules Explained',
'duration': 207, 'duration': 208,
'description': 'A new clip from Red Bull sees Daniel Ricciardo and Sebastian Vettel explain the 2014 Formula One regulations which are arguably the most complex the sport has ever seen.', 'description': 'A new clip from Red Bull sees Daniel Ricciardo and Sebastian Vettel explain the 2014 Formula One regulations which are arguably the most complex the sport has ever seen.',
'uploader': 'rainiere', 'uploader': 'mcomstaff',
'thumbnail': r're:^http://.*motorsport\.com/.+\.jpg$' 'uploader_id': 'UC334JIYKkVnyFoNCclfZtHQ',
} 'upload_date': '20140903',
'thumbnail': r're:^https?://.+\.jpg$'
},
'add_ie': ['Youtube'],
'params': {
'skip_download': True,
},
} }
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id) webpage = self._download_webpage(url, display_id)
flashvars_code = self._html_search_regex( iframe_path = self._html_search_regex(
r'<embed id="player".*?flashvars="([^"]+)"', webpage, 'flashvars') r'<iframe id="player_iframe"[^>]+src="([^"]+)"', webpage,
flashvars = compat_parse_qs(flashvars_code) 'iframe path')
params = json.loads(flashvars['parameters'][0]) iframe = self._download_webpage(
compat_urlparse.urljoin(url, iframe_path), display_id,
e = compat_str(int(time.time()) + 24 * 60 * 60) 'Downloading iframe')
base_video_url = params['location'] + '?e=' + e youtube_id = self._search_regex(
s = 'h3hg713fh32' r'www.youtube.com/embed/(.{11})', iframe, 'youtube id')
h = hashlib.md5((s + base_video_url).encode('utf-8')).hexdigest()
video_url = base_video_url + '&h=' + h
uploader = self._html_search_regex(
r'(?s)<span class="label">Video by: </span>(.*?)</a>', webpage,
'uploader', fatal=False)
return { return {
'id': params['video_id'], '_type': 'url_transparent',
'display_id': display_id, 'display_id': display_id,
'title': params['title'], 'url': 'https://youtube.com/watch?v=%s' % youtube_id,
'url': video_url,
'description': params.get('description'),
'thumbnail': params.get('main_thumb'),
'duration': int_or_none(params.get('duration')),
'uploader': uploader,
} }