app.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var http = require('http');
  2. var request = require('request');
  3. var fs = require('fs');
  4. var url = require('url');
  5. var ljConst = require("./const/LjConst.js");
  6. var CourseDown = require("./CourseDown");
  7. var async = require("async");
  8. var express = require('express');
  9. var app = express();
  10. //引入工具类
  11. var logHelper = require("./helper/LjLogHelper.js");
  12. var httpHelper = require("./helper/LjHttpHelper");
  13. var fileHelper = require("./helper/LjFileHelper");
  14. var apiHelper = require("./helper/LjApiHelper");
  15. var ljStringHelper = require("./helper/LjStringHelper");
  16. var videoUrl1 = 'https://efunvideo.ai160.com/vs2m/001/00101002/00101002002/00101002002.m3u8';
  17. var videoUrl2 = 'https://efunvideo.ai160.com/vs2m/801/C-01-01-0004/J-03-02-000365/J-03-02-000365.m3u8';
  18. var imgUrl = 'https://efunimgs.ai160.com/resources/J/02/01/500001.jpg';
  19. //downloadFile(videoUrl1);
  20. //downloadFile(videoUrl2);
  21. //fileHelper.downloadFile(imgUrl);
  22. var result = JSON.parse(fs.readFileSync("./lessonInfo.json"));
  23. CourseDown.downCourse(result,function()
  24. {
  25. console.info("周现广");
  26. });
  27. /**
  28. * 下载
  29. */
  30. app.get('/down.do', function (req, res)
  31. {
  32. var arg = url.parse(req.url, true).query;
  33. var courseId = arg.courseId;
  34. var eid = arg.eid;
  35. var uid = arg.uid;
  36. var token = arg.token;
  37. var lessonId = arg.lessonId;
  38. //获取参数
  39. logHelper.info(arg);
  40. //校验参数
  41. if (ljStringHelper.isNull(courseId))
  42. {
  43. logHelper.info("null object of courseId");
  44. return "null object of courseId";
  45. }
  46. if (ljStringHelper.isNull(lessonId))
  47. {
  48. logHelper.info("null object of lessonId");
  49. return "null object of courseId";
  50. }
  51. if (ljStringHelper.isNull(eid))
  52. {
  53. logHelper.info("null object of eid");
  54. return "null object of eid";
  55. }
  56. if (ljStringHelper.isNull(uid))
  57. {
  58. logHelper.info("null object of uid");
  59. return "null object of uid";
  60. }
  61. if (ljStringHelper.isNull(token))
  62. {
  63. logHelper.info("null object of token");
  64. return "null object of token";
  65. }
  66. var opt = {};
  67. opt.eid = "100166681101003";
  68. opt.uid = "100166681101001";
  69. opt.token = token;
  70. opt.lessonId = "02279ace371a11e8af2000163e08bde8";
  71. courseId = "02549160371e11e88c3600163e08bde8";
  72. opt.url = apiHelper.getApiForCourse(lessonId, courseId, eid);
  73. httpHelper.request(opt, function (error, res, body)
  74. {
  75. logHelper.info(body);
  76. let obj = JSON.parse(body);
  77. logHelper.info(obj.code);
  78. var result = JSON.parse(body);
  79. CourseDown.downCourse(result);
  80. });
  81. });
  82. //启动监听
  83. app.listen(9095, function ()
  84. {
  85. logHelper.info("winBoxNode starting success");
  86. });