pre.js 7.3 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
var VODS = [];
 if (!String.prototype.includes) {
    String.prototype.includes = function (search, start) {

      if (typeof start !== 'number') {
        start = 0;
      }

      if (start + search.length > this.length) {
        return false;
      } else {
        return this.indexOf(search, start) !== -1;
      }
    };
  }

  if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, 'includes', {
      value: function (searchElement, fromIndex) {

        if (this == null) {//this是空或者未定义,抛出错误
          throw new TypeError('"this" is null or not defined');
        }

        var o = Object(this);//将this转变成对象
        var len = o.length >>> 0;//无符号右移0位,获取对象length属性,如果未定义就会变成0

        if (len === 0) {//length为0直接返回false未找到目标值
          return false;
        }

        var n = fromIndex | 0;//查找起始索引
        var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);//计算正确起始索引,因为有可能是负值

        while (k < len) {//从起始索引处开始循环
          if (o[k] === searchElement) {//如果某一位置与寻找目标相等,返回true,找到了
            return true;
          }
          k++;
        }
        return false;//未找到,返回false
      }
    });
  }
H
hjdhnx 已提交
45 46 47 48 49 50 51 52 53 54 55
if (typeof String.prototype.startsWith != 'function') {
	String.prototype.startsWith = function (prefix){
		return this.slice(0, prefix.length) === prefix;
	};
}
if (typeof String.prototype.endsWith != 'function') {
	String.prototype.endsWith = function(suffix) {
		return this.indexOf(suffix, this.length - suffix.length) !== -1;
	};
}

H
hjdhnx 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
Object.assign = function () {
	var target = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i];
        for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
                target[key] = source[key];
            }
        }
    }
    return target;
};
Object.prototype.myValues=function(obj){
   if(obj ==null) {
   	 throw new TypeError("Cannot convert undefined or null to object");
   }
   var res=[]
   for(var k in obj){
     if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
   		res.push(obj[k]);
   	 }
   }
   return res;
}
H
hjdhnx 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
if (typeof Object.prototype.values != 'function') {
	Object.prototype.values=function(obj){
   if(obj ==null) {
   	 throw new TypeError("Cannot convert undefined or null to object");
   }
   var res=[]
   for(var k in obj){
     if(obj.hasOwnProperty(k)){//需判断是否是本身的属性
   		res.push(obj[k]);
   	 }
   }
   return res;
}
}

H
hjdhnx 已提交
95
Array.prototype.join = function (emoji) {
96 97
    // emoji = emoji||',';
    emoji = emoji||'';
H
hjdhnx 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110
      let self = this;
      let str = "";
      let i = 0;
      if (!Array.isArray(self)) {throw String(self)+'is not Array'}
      if(self.length===0){return ''}
      if (self.length === 1){return String(self[0])}
      i = 1;
      str = this[0];
      for (; i < self.length; i++) {
        str += String(emoji)+String(self[i]);
      }
      return str;
};
H
hjdhnx 已提交
111
Array.prototype.append = Array.prototype.push;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
function 是否正版(vipUrl){
    let flag = new RegExp('qq\.com|iqiyi\.com|youku\.com|mgtv\.com|bilibili\.com|sohu\.com|ixigua\.com|pptv\.com|miguvideo\.com|le\.com|1905\.com|fun\.tv');
    return  flag.test(vipUrl);
}
function urlDeal(vipUrl){
    if(!vipUrl){
        return ''
    }
    if(!是否正版(vipUrl)){
        return vipUrl
    }
    if(!/miguvideo/.test(vipUrl)){
        vipUrl=vipUrl.split('#')[0].split('?')[0];
    }
    return vipUrl
}
H
hjdhnx 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
function setResult(d){
    if(!Array.isArray(d)){
        return []
    }
    d.forEach(function (it){
        let obj = {
            vod_id:it.url||'',
            vod_name: it.title||'',
            vod_remarks: it.desc||'',
            vod_content: it.content||'',
            vod_pic: it.pic_url||it.img||'',
        };
        let keys = Object.keys(it);
        if(keys.includes('tname')){
            obj.type_name = it.tname||'';
        }
        if(keys.includes('tid')){
            obj.type_id = it.tid||'';
        }
        if(keys.includes('year')){
            obj.vod_year = it.year||'';
        }
        if(keys.includes('actor')){
            obj.vod_actor = it.actor||'';
        }
        if(keys.includes('director')){
            obj.vod_director = it.director||'';
        }
        if(keys.includes('area')){
            obj.vod_area = it.area||'';
        }
        VODS.push(obj);
    });
    return VODS
}
H
hjdhnx 已提交
163
function setResult2(res){
H
hjdhnx 已提交
164
    VODS = res.list||[];
H
hjdhnx 已提交
165 166 167 168 169 170 171 172
    return VODS
}
function setHomeResult(res){
    if(!res||typeof(res)!=='object'){
        return []
    }
    return setResult(res.list);
}
H
hjdhnx 已提交
173
// 千万不要用for in 推荐 forEach (for in 会打乱顺序)
174
//猫函数
H
hjdhnx 已提交
175 176 177
function maoss(jxurl, ref, key) {
    eval(getCryptoJS());
    try {
178 179
        var getVideoInfo = function (text) {
                return CryptoJS.AES.decrypt(text, key, {iv: iv, padding: CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8);
H
hjdhnx 已提交
180 181 182 183 184 185 186 187 188 189 190
        };
        var token_key = key == undefined ? 'dvyYRQlnPRCMdQSe' : key;
        if (ref) {
            var html = request(jxurl, {
                headers: {
                    'Referer': ref
                }
            });
        } else {
            var html = request(jxurl);
        }
191
        // print(html);
H
hjdhnx 已提交
192 193 194 195 196 197
        if (html.indexOf('&btwaf=') != -1) {
            html = request(jxurl + '&btwaf' + html.match(/&btwaf(.*?)"/)[1], {
                headers: {
                    'Referer': ref
                }
            })
198
        }
H
hjdhnx 已提交
199 200 201 202 203
        var token_iv = html.split('_token = "')[1].split('"')[0];
        var key = CryptoJS.enc.Utf8.parse(token_key);
        var iv = CryptoJS.enc.Utf8.parse(token_iv);
        // log("iv:"+iv);
        //  log(html);
204 205
        // print(key);
        // print(iv);
H
hjdhnx 已提交
206
        eval(html.match(/var config = {[\s\S]*?}/)[0] + '');
207 208 209
        // config.url = config.url.replace(/,/g,'');
        // print(config.url);
        if (!config.url.startsWith('http')) {
H
hjdhnx 已提交
210 211 212 213 214 215 216 217 218 219
            //config.url = decodeURIComponent(AES(config.url, key, iv));
            config.url = CryptoJS.AES.decrypt(config.url, key, {
                iv: iv,
                padding: CryptoJS.pad.Pkcs7
            }).toString(CryptoJS.enc.Utf8)
        }
        return config.url;
    } catch (e) {
        return '';
    }
H
hjdhnx 已提交
220 221 222
}

function request(url,obj){
223 224
    // obj = obj||{'user-agent': MOBILE_UA};
    let new_obj;
H
hjdhnx 已提交
225
    if(typeof(fetch_params)!=='undefined'){
226
        new_obj = obj?Object.assign(fetch_params,obj):fetch_params;
H
hjdhnx 已提交
227
    }else{
228 229
        new_obj = obj||{}
    }
H
hjdhnx 已提交
230
    if(!new_obj||!new_obj.headers||(!new_obj.headers['User-Agent']&&!new_obj.headers['user-agent'])){
231
        new_obj.headers['User-Agent'] = MOBILE_UA;
H
hjdhnx 已提交
232
    }
233
    // delete new_obj.headers['Referer'];
H
hjdhnx 已提交
234 235
    // print(obj);
    if(typeof(fetch)!==undefined){
236
        let html = fetch(url,new_obj);
H
hjdhnx 已提交
237 238 239
        if (/\?btwaf=/.test(html)) {//宝塔验证
            url=url.split('#')[0]+'?btwaf'+html.match(/btwaf(.*?)\"/)[1];
            log("宝塔验证跳转到:"+url);
240
            html = fetch(url, new_obj);
H
hjdhnx 已提交
241 242 243 244
        }
        return html
    }
    return ''
H
hjdhnx 已提交
245 246 247 248 249 250 251 252
}

function urlencode (str) {
    str = (str + '').toString();

    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}