ScutProvider

Untitled

Nov 18th, 2020
345
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getPreferredFormatIndex = (formats, url) => {
  2.   const preferences = JSON.parse(window.localStorage.getItem(process.env.localStorageFormatRecordName)) || {};
  3.   let domainPreferences = preferences[_getDomain(url)];
  4.   if (!(domainPreferences && domainPreferences.length)) {
  5.     domainPreferences = preferences["youtube.com"];
  6.   }
  7.   if (!(domainPreferences && domainPreferences.length)) {
  8.     domainPreferences = process.env.defaultFormatArray;
  9.   }
  10.  
  11.   if (formats && formats.length) {    
  12.     const formatId = domainPreferences[domainPreferences.length - 1];
  13.     const byIdIndex = formatId && formats.findIndex(item => item.formatId === formatId);
  14.    
  15.     if (byIdIndex && byIdIndex >= 0) {
  16.       return byIdIndex;        
  17.     } else {
  18.       const maxIntersectionIndex = _maxIntersectionIndex(formats, domainPreferences);
  19.       if (maxIntersectionIndex && maxIntersectionIndex >=0) {
  20.         return maxIntersectionIndex;
  21.       } else {
  22.         return 0;
  23.       }        
  24.     }
  25.   } else {
  26.     return 0;
  27.   }
  28. }
RAW Paste Data