video.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var video = {
  2. getVideoSource(vids, videoEls) {
  3. // let vids = ['8892551']
  4. // var videoEls = {
  5. // '8892551': 'lookup',
  6. // }
  7. var mp4UrlMap = {}
  8. $.ajax({
  9. type: "GET",
  10. dataType: "json",
  11. url: `//video.duowan.com/jsapi/playPageVideoInfo/?vids=${vids.join(',')}`,
  12. success: function(data) {
  13. for(var i in data) {
  14. let resouce = video.deCodeArg(data[i].c).all,
  15. source = resouce.yuanhua || resouce[1300] || resouce[1000] || resouce[350]
  16. let name = videoEls[i]
  17. mp4UrlMap[name] = source.src
  18. }
  19. console.log(mp4UrlMap)
  20. for(var key in mp4UrlMap) {
  21. document.getElementById(key).src = mp4UrlMap[key]
  22. }
  23. }
  24. })
  25. },
  26. decr(r) {
  27. var e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@!~*-_.()'".split("");
  28. var n = [];
  29. var a = [];
  30. r.split("").reverse().forEach(function (r, t) {
  31. var o = e.indexOf(r);
  32. if (parseInt((t + 1) % 2) == 1) {
  33. a.push(o)
  34. } else {
  35. var p = parseInt(o - a[(t + 1) / 2 - 1]);
  36. n.push(e[p])
  37. }
  38. });
  39. var t = n.join("").replace(/@/g, "%");
  40. return decodeURIComponent(t)
  41. },
  42. /**
  43. * 解密数据
  44. */
  45. deCodeArg(target) {
  46. var srcMap = {};
  47. if (JSON.parse) {
  48. srcMap = JSON.parse(this.decr(target));
  49. } else {
  50. srcMap = eval('(' + this.decr(target) + ')');
  51. }
  52. return srcMap;
  53. },
  54. }
  55. export default video