Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeoMix/c2b194a20b6c20c1c69e to your computer and use it in GitHub Desktop.
Save MeoMix/c2b194a20b6c20c1c69e to your computer and use it in GitHub Desktop.
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