push_agent.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * @File : push_agent.js
  3. * @Author : jade
  4. * @Date : 2024/3/6 9:30
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {Spider} from "./spider.js";
  10. import {VodDetail} from "../lib/vod.js";
  11. import * as Utils from "../lib/utils.js";
  12. import {detailContent, initAli, playContent} from "../lib/ali.js";
  13. class PushSpider extends Spider {
  14. constructor() {
  15. super();
  16. }
  17. getName() {
  18. return "┃推送┃"
  19. }
  20. getAppName() {
  21. return "推送"
  22. }
  23. getJSName() {
  24. return "push"
  25. }
  26. getType() {
  27. return 4
  28. }
  29. async init(cfg) {
  30. try {
  31. this.cfgObj = await this.SpiderInit(cfg)
  32. this.catOpenStatus = this.cfgObj.CatOpenStatus
  33. await initAli(this.cfgObj["token"]);
  34. } catch (e) {
  35. await this.jadeLog.error(`初始化失败,失败原因为:${e}`)
  36. }
  37. }
  38. async check(args){
  39. // CatVodOpen目前支持http链接和https链接
  40. await spider.jadeLog.debug(`剪切板输入内容为:${args}`)
  41. if (this.catOpenStatus){
  42. return !!args.startsWith("http");
  43. }else{
  44. // TV目前支持http链接和https链接和Ftp和magnet等格式
  45. return !!(args.startsWith("http") || args.startsWith("ftp") || args.startsWith("magnet"));
  46. }
  47. }
  48. async parseVodDetailfromJson(id) {
  49. let vodDetail = new VodDetail()
  50. vodDetail.vod_pic = Utils.RESOURCEURL + "/resources/push.jpg"
  51. let mather = Utils.patternAli.exec(id)
  52. if (mather !== null && mather.length > 0) {
  53. let aliVodDetail = await detailContent([id])
  54. vodDetail.vod_play_url = aliVodDetail.vod_play_url
  55. vodDetail.vod_play_from = aliVodDetail.vod_play_from
  56. } else {
  57. vodDetail.vod_play_from = '推送';
  58. vodDetail.vod_play_url = '推送$' + id;
  59. }
  60. return vodDetail
  61. }
  62. async setDetail(id) {
  63. this.vodDetail = await this.parseVodDetailfromJson(id)
  64. }
  65. async setPlay(flag, id, flags) {
  66. if (flag === "推送"){
  67. this.playUrl = id
  68. }else{
  69. this.playUrl = JSON.parse(await playContent(flag, id, flags))["url"];
  70. }
  71. }
  72. }
  73. let spider = new PushSpider()
  74. async function check(args) {
  75. return await spider.check(args)
  76. }
  77. async function init(cfg) {
  78. await spider.init(cfg)
  79. }
  80. async function detail(id) {
  81. return await spider.detail(id)
  82. }
  83. async function play(flag, id, flags) {
  84. return await spider.play(flag, id, flags)
  85. }
  86. export function __jsEvalReturn() {
  87. return {
  88. support: check, init: init, detail: detail, play: play,
  89. };
  90. }
  91. export {spider}