Last active
August 29, 2015 14:25
-
-
Save MeoMix/c2b194a20b6c20c1c69e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var decodedResponse = decodeURIComponent(this.response); | |
// The 'adaptive-fmts' parameter stores the video information needed. | |
var encodedAdaptiveFormats = (decodedResponse.split('adaptive_fmts=')[1] || '').replace(/\+/g, ' '); | |
var encodedAdaptiveFormatList = encodedAdaptiveFormats.split(','); | |
// Convert the encoded URL of adaptive formats into an array of objects since that's a lot easier to work with. | |
var decodedAdaptiveFormatList = encodedAdaptiveFormatList.map(function(encodedAdaptiveFormat) { | |
var decodedAdaptiveFormat = {}; | |
encodedAdaptiveFormat.split('&').forEach(function(parameterPair) { | |
var parameterKeyValue = parameterPair.split('='); | |
var key = decodeURIComponent(parameterKeyValue[0]); | |
var value = decodeURIComponent(parameterKeyValue[1]); | |
decodedAdaptiveFormat[key] = value; | |
}); | |
return decodedAdaptiveFormat; | |
}); | |
// Some of the video information received is for 'related videos' which needs to be discarded. | |
// To do so, detect type/size on the video information because that indicates its for the current video. | |
// Also check that the type is 'video' because it could contain audio information. | |
videoInfoList = decodedAdaptiveFormatList.filter(function(object) { | |
return !!object.type && !!object.size && object.type.indexOf('video') !== -1; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment