testSpider.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {__jsEvalReturn} from './bilibili.js';
  2. import * as Utils from "../lib/utils.js";
  3. let spider = __jsEvalReturn();
  4. async function testPlay(vodDetail) {
  5. if (vodDetail.list && vodDetail.list.length > 0) {
  6. const pFlag = vodDetail.list[0].vod_play_from.split('$$$');
  7. const pUrls = vodDetail.list[0].vod_play_url.split('$$$');
  8. if (pFlag.length > 0 && pUrls.length > 0) {
  9. for (const i in pFlag) {
  10. // console.debug(i)
  11. let flag = pFlag[i];
  12. let urls = pUrls[i].split('#');
  13. // console.debug(flag, urls)
  14. for (const j in urls) {
  15. var name = urls[j].split('$')[0];
  16. var url = urls[j].split('$')[1];
  17. console.debug(flag + " | " + name + " | " + url);
  18. var playUrl = await spider.play(flag, url, []);
  19. console.debug('playURL: ' + playUrl);
  20. }
  21. }
  22. }
  23. }
  24. }
  25. async function testMusicPlay(vodDetail) {
  26. if (vodDetail.list && vodDetail.list.length > 0) {
  27. const pFlag = vodDetail.list[0].volumes.split('$$$');
  28. const pUrls = vodDetail.list[0].urls.split('$$$');
  29. if (pFlag.length > 0 && pUrls.length > 0) {
  30. for (const i in pFlag) {
  31. // console.debug(i)
  32. let flag = pFlag[i];
  33. let urls = pUrls[i].split('#');
  34. // console.debug(flag, urls)
  35. for (const j in urls) {
  36. var name = urls[j].split('$')[0];
  37. var url = urls[j].split('$')[1];
  38. console.debug(flag + " | " + name + " | " + url);
  39. var playUrl = await spider.play(flag, url, []);
  40. console.debug('playURL: ' + playUrl);
  41. }
  42. break
  43. }
  44. }
  45. }
  46. }
  47. async function test() {
  48. let siteKey = 'bilibili';
  49. let siteType = 0;
  50. await spider.init({
  51. skey: siteKey, stype: siteType, ext: {
  52. "token": "6827db23e5474d02a07fd7431d3d5a5a",
  53. "box": "TV",
  54. "code": "1",
  55. "from": "justlive1",
  56. "danmu": true,
  57. "cookie": "buvid3=02675249-8ED3-C418-87F5-59E18316459714816infoc; b_nut=1704421014; _uuid=5D435F74-F574-D9AB-62C1-B9294DE465D913102infoc; buvid_fp=e8c5650c749398e9b5cad3f3ddb5081e; buvid4=007E85D1-52C1-7E6E-07CF-837FFBC9349516677-024010502-J5vTDSZDCw4fNnXRejbSVg%3D%3D; rpdid=|()kYJmulRu0J'u~|RRJl)JR; PVID=1; SESSDATA=3be091d3%2C1720332009%2C699ed%2A11CjAcCdwXG5kY1umhCOpQHOn_WP7L9xFBfWO7KKd4BPweodpR6VyIfeNyPiRmkr5jCqsSVjg0R0dZOVVHRUo3RnhPRTZFc3JPbGdiUjFCdHpiRDhiTkticmdKTjVyS1VhbDdvNjFMSDJlbUJydUlRdjFUNGFBNkJlV2ZTa0N1Q1BEVi1QYTQzTUh3IIEC; bili_jct=b0ee7b5d3f27df893545d811d95506d4; DedeUserID=78014638; DedeUserID__ckMd5=4c8c5d65065e468a; enable_web_push=DISABLE; header_theme_version=CLOSE; home_feed_column=5; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; b_lsid=75E916AA_18EA1A8D995; bsource=search_baidu; FEED_LIVE_VERSION=V_HEADER_LIVE_NO_POP; browser_resolution=1507-691; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTIzNjk5MTMsImlhdCI6MTcxMjExMDY1MywicGx0IjotMX0.8zQW_fNTCSBlK_JkHnzu3gDw62wuTK1qgKcbGec3swM; bili_ticket_expires=171236985"
  58. }
  59. });
  60. let classes = JSON.parse(await spider.home(true));
  61. console.debug(JSON.stringify(classes))
  62. // //测试首页列表
  63. let homeVod = JSON.parse(await spider.homeVod())
  64. console.debug(JSON.stringify(homeVod));
  65. //测试分类列表
  66. let catePage = JSON.parse(await spider.category("历史记录", "1", undefined, {}));
  67. console.debug(JSON.stringify(catePage));
  68. // 测试详情
  69. let detail1 = JSON.parse(await spider.detail("BV12r421t7nu"))
  70. await testPlay(detail1)
  71. // 测试搜索
  72. let search_page = JSON.parse(await spider.search("海贼王"))
  73. console.debug(JSON.stringify(search_page));
  74. // 测试详情
  75. if (search_page.list && search_page.list.length > 0) {
  76. for (const k in search_page.list) {
  77. // console.debug(k)
  78. if (k >= 1) break;
  79. let obj = search_page.list[k]
  80. let spVid = search_page.list[k].vod_id
  81. console.debug("===", spVid)
  82. var detail = JSON.parse(await spider.detail(spVid || search_page.list[k].vod_id));
  83. await testPlay(detail);
  84. }
  85. }
  86. }
  87. export {test};