2014-04-03 18:05:43 -04:00
# coding: utf-8
from __future__ import unicode_literals
import hashlib
import json
import time
from . common import InfoExtractor
2014-12-13 06:24:42 -05:00
from . . compat import (
2014-04-03 18:05:43 -04:00
compat_parse_qs ,
compat_str ,
2014-12-13 06:24:42 -05:00
)
from . . utils import (
2014-04-03 18:05:43 -04:00
int_or_none ,
)
class MotorsportIE ( InfoExtractor ) :
IE_DESC = ' motorsport.com '
_VALID_URL = r ' http://www \ .motorsport \ .com/[^/?#]+/video/(?:[^/?#]+/)(?P<id>[^/]+)/(?:$|[?#]) '
_TEST = {
' url ' : ' http://www.motorsport.com/f1/video/main-gallery/red-bull-racing-2014-rules-explained/ ' ,
' md5 ' : ' 5592cb7c5005d9b2c163df5ac3dc04e4 ' ,
' info_dict ' : {
' id ' : ' 7063 ' ,
' ext ' : ' mp4 ' ,
' title ' : ' Red Bull Racing: 2014 Rules Explained ' ,
' duration ' : 207 ,
' 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 ' ,
' thumbnail ' : r ' re:^http://.*motorsport \ .com/.+ \ .jpg$ '
}
}
def _real_extract ( self , url ) :
2014-12-13 06:24:42 -05:00
display_id = self . _match_id ( url )
2014-04-03 18:05:43 -04:00
webpage = self . _download_webpage ( url , display_id )
2014-12-13 06:24:42 -05:00
2014-04-03 18:05:43 -04:00
flashvars_code = self . _html_search_regex (
r ' <embed id= " player " .*?flashvars= " ([^ " ]+) " ' , webpage , ' flashvars ' )
flashvars = compat_parse_qs ( flashvars_code )
params = json . loads ( flashvars [ ' parameters ' ] [ 0 ] )
e = compat_str ( int ( time . time ( ) ) + 24 * 60 * 60 )
base_video_url = params [ ' location ' ] + ' ?e= ' + e
s = ' h3hg713fh32 '
2014-04-04 17:06:27 -04:00
h = hashlib . md5 ( ( s + base_video_url ) . encode ( ' utf-8 ' ) ) . hexdigest ( )
2014-04-03 18:05:43 -04:00
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 {
' id ' : params [ ' video_id ' ] ,
' display_id ' : display_id ,
' title ' : params [ ' title ' ] ,
' url ' : video_url ,
' description ' : params . get ( ' description ' ) ,
' thumbnail ' : params . get ( ' main_thumb ' ) ,
' duration ' : int_or_none ( params . get ( ' duration ' ) ) ,
' uploader ' : uploader ,
}