push_agent.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 {_} from "../lib/cat.js";
  10. import {Spider} from "./spider.js";
  11. import {VodDetail} from "../lib/vod.js";
  12. import * as Utils from "../lib/utils.js";
  13. import { detailContent,initCloud,playContent,getHeaders} from "../lib/cloud.js";
  14. class PushSpider extends Spider {
  15. constructor() {
  16. super();
  17. }
  18. getName() {
  19. return "┃推送┃"
  20. }
  21. getAppName() {
  22. return "推送"
  23. }
  24. getJSName() {
  25. return "push"
  26. }
  27. getType() {
  28. return 4
  29. }
  30. async init(cfg) {
  31. try {
  32. this.cfgObj = await this.SpiderInit(cfg)
  33. this.catOpenStatus = this.cfgObj.CatOpenStatus
  34. await initCloud(this.cfgObj);
  35. } catch (e) {
  36. await this.jadeLog.error(`初始化失败,失败原因为:${e}`)
  37. }
  38. }
  39. async check(args){
  40. // CatVodOpen目前支持http链接和https链接
  41. await spider.jadeLog.debug(`剪切板输入内容为:${args}`)
  42. if (this.catOpenStatus){
  43. return !!args.startsWith("http");
  44. }else{
  45. // TV目前支持http链接和https链接和Ftp和magnet等格式
  46. return !!(args.startsWith("http") || args.startsWith("ftp") || args.startsWith("magnet"));
  47. }
  48. }
  49. async parseVodDetailfromJson(id) {
  50. let vodDetail = new VodDetail()
  51. vodDetail.vod_pic = Utils.RESOURCEURL + "/resources/push.jpg"
  52. let mather = Utils.patternAli.exec(id)
  53. let quarkMatcher = Utils.patternQuark.exec(id)
  54. if (mather !== null && mather.length > 0) {
  55. let playVod = await detailContent([id])
  56. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  57. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  58. } else if (quarkMatcher !== null && quarkMatcher.length > 0){
  59. let playVod = await detailContent([id])
  60. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  61. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  62. }else {
  63. vodDetail.vod_play_from = '推送';
  64. vodDetail.vod_play_url = '推送$' + id;
  65. }
  66. return vodDetail
  67. }
  68. async setDetail(id) {
  69. this.vodDetail = await this.parseVodDetailfromJson(id)
  70. }
  71. async setPlay(flag, id, flags) {
  72. if (flag === "推送"){
  73. this.playUrl = id
  74. }else{
  75. this.playUrl = await playContent(flag, id, flags);
  76. this.result.setHeader(getHeaders(flag))
  77. }
  78. }
  79. }
  80. let spider = new PushSpider()
  81. async function check(args) {
  82. return await spider.check(args)
  83. }
  84. async function init(cfg) {
  85. await spider.init(cfg)
  86. }
  87. async function detail(id) {
  88. return await spider.detail(id)
  89. }
  90. async function play(flag, id, flags) {
  91. return await spider.play(flag, id, flags)
  92. }
  93. export function __jsEvalReturn() {
  94. return {
  95. support: check, init: init, detail: detail, play: play,
  96. };
  97. }
  98. export {spider}