2014-01-22 07:03:46 +08:00
from __future__ import unicode_literals
2015-12-03 20:47:21 +08:00
from . common import InfoExtractor
from . . utils import (
int_or_none ,
parse_age_limit ,
url_basename ,
)
2013-06-24 02:29:46 +08:00
2013-12-03 21:58:24 +08:00
2015-12-03 20:47:21 +08:00
class GametrailersIE ( InfoExtractor ) :
2016-03-21 23:36:32 +08:00
_VALID_URL = r ' https?://www \ .gametrailers \ .com/videos/view/[^/]+/(?P<id>.+) '
2015-12-03 20:47:21 +08:00
2013-06-28 02:46:46 +08:00
_TEST = {
2015-12-03 20:47:21 +08:00
' url ' : ' http://www.gametrailers.com/videos/view/gametrailers-com/116437-Just-Cause-3-Review ' ,
' md5 ' : ' f28c4efa0bdfaf9b760f6507955b6a6a ' ,
2014-01-22 07:03:46 +08:00
' info_dict ' : {
2015-12-03 20:47:21 +08:00
' id ' : ' 2983958 ' ,
2014-02-12 02:50:53 +08:00
' ext ' : ' mp4 ' ,
2015-12-03 20:47:21 +08:00
' display_id ' : ' 116437-Just-Cause-3-Review ' ,
' title ' : ' Just Cause 3 - Review ' ,
' description ' : ' It \' s a lot of fun to shoot at things and then watch them explode in Just Cause 3, but should there be more to the experience than that? ' ,
2013-06-28 02:46:46 +08:00
} ,
}
2013-07-14 20:29:15 +08:00
2015-12-03 20:47:21 +08:00
def _real_extract ( self , url ) :
display_id = self . _match_id ( url )
webpage = self . _download_webpage ( url , display_id )
title = self . _html_search_regex (
r ' <title>(.+?) \ | ' , webpage , ' title ' ) . strip ( )
embed_url = self . _proto_relative_url (
self . _search_regex (
r ' src= \' (//embed.gametrailers.com/embed/[^ \' ]+) \' ' , webpage ,
' embed url ' ) ,
scheme = ' http: ' )
video_id = url_basename ( embed_url )
embed_page = self . _download_webpage ( embed_url , video_id )
embed_vars_json = self . _search_regex (
r ' (?s)var embedVars = ( \ { .*? \ }) \ s*</script> ' , embed_page ,
' embed vars ' )
info = self . _parse_json ( embed_vars_json , video_id )
formats = [ ]
for media in info [ ' media ' ] :
if media [ ' mediaPurpose ' ] == ' play ' :
formats . append ( {
' url ' : media [ ' uri ' ] ,
' height ' : media [ ' height ' ] ,
' width: ' : media [ ' width ' ] ,
} )
self . _sort_formats ( formats )
return {
' id ' : video_id ,
' display_id ' : display_id ,
' title ' : title ,
' formats ' : formats ,
' thumbnail ' : info . get ( ' thumbUri ' ) ,
' description ' : self . _og_search_description ( webpage ) ,
' duration ' : int_or_none ( info . get ( ' videoLengthInSeconds ' ) ) ,
' age_limit ' : parse_age_limit ( info . get ( ' audienceRating ' ) ) ,
}