dd_videoShow.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const axios = require("axios");
  2. const cheerio = require('cheerio');
  3. var go = true;
  4. async function getVideoInfo(url, page) { // url 最好以/结尾
  5. console.log(url, page);
  6. if (page != 1) {
  7. url += `page/${page}/`;
  8. }
  9. var res = await axios.get(url, {
  10. headers: {
  11. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  12. }
  13. });
  14. var $ = cheerio.load(res.data);
  15. // console.log($('.post-box-container').length);
  16. if($('.next.page-numbers').length >= 1) {
  17. go = true;
  18. } else {
  19. go = false;
  20. }
  21. var arr = [];
  22. $('.post-box-container').each((i, m) => {
  23. var thumb = $('.post-box-image', m).attr('style');
  24. thumb = /.*\((.*)\)/g.exec(thumb)[1];
  25. var label = $('.post-box-meta', m).text();
  26. var tags = [];
  27. $('.post-box-meta a', m).each((i, m) => {
  28. var json = {
  29. title: $(m).text(),
  30. url: $(m).attr('href')
  31. }
  32. tags.push(json);
  33. })
  34. var title = $('.post-box-title', m).text();
  35. var video_url = $('.post-box-title > a', m).attr('href');
  36. var summary = $('.post-box-text > p', m).text();
  37. var json = {
  38. thumb: thumb,
  39. label: label,
  40. tags: tags,
  41. title: title,
  42. video_url: video_url,
  43. summary: summary
  44. }
  45. arr.push(json);
  46. });
  47. return arr;
  48. }
  49. module.exports = {
  50. type: 'list',
  51. async fetch({page, args}) {
  52. page = page || 1;
  53. this.title = args.title;
  54. var arr = await getVideoInfo(args.url, page);
  55. var data = arr.map(m => {
  56. return {
  57. style: 'vod',
  58. thumb: m.thumb,
  59. label: m.label,
  60. title: m.title,
  61. summary: m.summary,
  62. route: $route('dd_js', {
  63. title: m.title,
  64. url: m.video_url
  65. }),
  66. // onLongClick: async () => {
  67. // let selected = await $input.select({
  68. // title: '分区查看',
  69. // options: m.tags
  70. // })
  71. // if (selected != null) {
  72. // $router.to($route('dd_js', {
  73. // url: selected.url
  74. // }))
  75. // }
  76. // }
  77. }
  78. })
  79. if (go) {
  80. return {
  81. nextPage: page + 1,
  82. items: data
  83. }
  84. } else {
  85. return data;
  86. }
  87. }
  88. }