斗鱼.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. js:
  2. //输入的input如:https://m.douyu.com/312212?dyshid=0-00000003333&dyshci=1
  3. function getSign(script, rid, did, tt){
  4. let result = script.match(/(function ub98484234.*)\s(var.*)/)[0];
  5. let func_ub9 = result.replace(/eval.*;}/, 'strc;}', result);
  6. eval(func_ub9);
  7. let res = ub98484234();
  8. let v = res.match(/v=(\d+)/)[0].replace("v=", '');
  9. let rb = md5(rid + did + tt + v);
  10. let func_sign = res.replace(/return rt;}\);?/, 'return rt;}');
  11. func_sign = func_sign.replace('(function (', 'function sign(');
  12. func_sign = func_sign.replace('CryptoJS.MD5(cb).toString()', '"' + rb + '"');
  13. eval(func_sign);
  14. let params = sign(rid, did, tt) + "&ver=219032101&rate=-1&rid="+rid;
  15. return params
  16. }
  17. // log(env);
  18. // fetch_params.headers.Referer = input;
  19. var flag = [];
  20. function lazy() {
  21. try {
  22. // realUrl = null;
  23. let html = request(input);
  24. // log(html);
  25. let rid = html.match(/rid":(.*?),"vipId/)[1];
  26. log(rid);
  27. // let tt = Date.parse(new Date()).toString().substr(0, 10);
  28. let tt = Math.round(new Date().getTime() / 1000).toString();
  29. let did = '10000000000000000000000000001501';
  30. let param_body = getSign(html, rid, did, tt);
  31. log(param_body);
  32. let stream_json = request('https://m.douyu.com/api/room/ratestream', {
  33. headers: {
  34. 'Content-Type': 'application/x-www-form-urlencoded',
  35. }, body: param_body, method: 'POST'
  36. });
  37. log(stream_json);
  38. let stream = JSON.parse(stream_json).data;
  39. realUrl = stream.url;
  40. log('解析到真实播放地址:' + realUrl);
  41. } catch (e) {
  42. log('解析发生错误:' + e.message);
  43. realUrl = input;
  44. }
  45. return realUrl
  46. }