star.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * @File : star.js
  3. * @Author : jade
  4. * @Date : 2024/2/21 10:36
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 星视界 需要翻墙
  8. */
  9. import {VodDetail, VodShort} from "../lib/vod.js"
  10. import * as Utils from "../lib/utils.js";
  11. import {Spider} from "./spider.js";
  12. import {_} from "../lib/cat.js";
  13. class StarSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://www.histar.tv"
  17. this.apiUrl = "https://aws.ulivetv.net"
  18. }
  19. getAppName() {
  20. return "星视界"
  21. }
  22. getName() {
  23. return "☄️┃星视界┃墙☄️"
  24. }
  25. getJSName() {
  26. return "star"
  27. }
  28. getType() {
  29. return 3
  30. }
  31. getApiHeader() {
  32. return {'User-Agent': Utils.MOBILEUA, "Content-Type": 'application/json'}
  33. }
  34. async setClasses() {
  35. let $ = await this.getHtml()
  36. let navElements = $($("[class=\"nav_nav__zgz60\"]")[0]).find("a")
  37. for (const navElement of navElements) {
  38. let type_id = navElement.attribs.href
  39. let type_name = $(navElement).text()
  40. if (type_id !== "/" && type_name !== "电视直播") {
  41. this.classes.push(this.getTypeDic(type_name, type_id))
  42. }
  43. }
  44. }
  45. convertTypeData(typeData, key, name) {
  46. if (!typeData || !typeData[key] || typeData[key].length <= 2) {
  47. return null;
  48. }
  49. let valueList = typeData[key];
  50. if (key === 'time') {
  51. valueList = valueList.sort((a, b) => {
  52. return b - a;
  53. });
  54. valueList.pop();
  55. }
  56. const values = _.map(valueList, (item) => {
  57. let name;
  58. let value;
  59. if (item instanceof Array) {
  60. name = item[0];
  61. value = item[0];
  62. } else {
  63. name = item.toString();
  64. value = item.toString();
  65. }
  66. return {
  67. n: name, v: value,
  68. };
  69. });
  70. values.unshift({
  71. n: '全部', v: '',
  72. });
  73. return {
  74. key: key, name: name, init: '', value: values,
  75. };
  76. }
  77. async getFilter($) {
  78. const json = $('#__NEXT_DATA__')[0].children[0].data;
  79. const obj = JSON.parse(json).props["pageProps"]["filterCondition"];
  80. const label = this.convertTypeData(obj, 'label', '类型');
  81. const country = this.convertTypeData(obj, 'country', '地区');
  82. const time = this.convertTypeData(obj, 'time', '年份');
  83. return [label, country, time];
  84. }
  85. async setFilterObj() {
  86. for (const type_dic of this.classes.slice(0, 4)) {
  87. let type_id = type_dic["type_id"]
  88. if (type_id !== "最近更新") {
  89. let url = this.siteUrl + `${type_id}/all/all/all`
  90. let $ = await this.getHtml(url)
  91. this.filterObj[type_id] = await this.getFilter($)
  92. }
  93. }
  94. }
  95. parseVodShortFromtJson(obj) {
  96. let vodShort = new VodShort()
  97. vodShort.vod_id = obj["id"]
  98. vodShort.vod_name = obj["name"]
  99. vodShort.vod_pic = obj["img"]
  100. if (_.isEmpty(vodShort.vod_pic)) {
  101. vodShort.vod_pic = obj["picurl"] ?? ""
  102. }
  103. vodShort.vod_remarks = obj["countStr"]
  104. if (_.isEmpty(vodShort.vod_remarks)) {
  105. vodShort.vod_remarks = obj["time"]
  106. }
  107. return vodShort
  108. }
  109. async parseVodShortListFromJson(obj) {
  110. let vod_list = []
  111. for (const results of obj) {
  112. let name = results["name"]
  113. if (name !== "电视直播") {
  114. let cards = results["cards"]
  115. for (const result of cards) {
  116. let vodShort = this.parseVodShortFromtJson(result)
  117. vod_list.push(vodShort)
  118. }
  119. }
  120. }
  121. return vod_list
  122. }
  123. async parseVodShortListFromJsonByCategory(obj) {
  124. let vod_list = []
  125. for (const result of obj.list) {
  126. let vodShort = this.parseVodShortFromtJson(result)
  127. vod_list.push(vodShort)
  128. }
  129. return vod_list
  130. }
  131. getObjectValues(objList,key){
  132. let value_list = []
  133. for (const result of objList){
  134. value_list.push(result[key])
  135. }
  136. return value_list
  137. }
  138. async parseVodDetailfromJson(obj) {
  139. const vObj = obj["collectionInfo"];
  140. let vodDetail = new VodDetail();
  141. vodDetail.vod_name = vObj["name"]
  142. vodDetail.type_name = vObj["chname"]
  143. vodDetail.vod_pic = vObj["picurl"]
  144. vodDetail.vod_area = vObj["country"]
  145. vodDetail.vod_remarks = vObj["countStr"]
  146. vodDetail.vod_actor = this.getObjectValues(vObj["actor"],"name").join("/")
  147. vodDetail.vod_director = this.getObjectValues(vObj["director"],"name").join("/")
  148. vodDetail.vod_content = vObj["desc"]
  149. const playInfo = vObj["videosGroup"];
  150. const playVod = {};
  151. _.each(playInfo, (info) => {
  152. const sourceName = info.name;
  153. let playList = '';
  154. const videoInfo = info["videos"];
  155. const vodItems = _.map(videoInfo, (epObj) => {
  156. const epName = "第" + epObj["eporder"] + "集";
  157. const playUrl = epObj["purl"]
  158. return epName + '$' + playUrl;
  159. });
  160. if (_.isEmpty(vodItems)) return;
  161. playList = vodItems.join('#');
  162. playVod[sourceName] = playList;
  163. });
  164. vodDetail.vod_play_from = _.keys(playVod).join('$$$');
  165. vodDetail.vod_play_url = _.values(playVod).join('$$$');
  166. return vodDetail
  167. }
  168. async setHomeVod() {
  169. let json = await this.fetch(this.apiUrl + "/v3/web/api/home?chName=首页", null, this.getApiHeader())
  170. const obj = JSON.parse(json)["data"]["cardsGroup"];
  171. this.homeVodList = await this.parseVodShortListFromJson(obj)
  172. }
  173. getClassChName(tid) {
  174. for (const class_dic of this.classes) {
  175. if (tid === class_dic["type_id"]) {
  176. return class_dic["type_name"]
  177. }
  178. }
  179. }
  180. async setCategory(tid, pg, filter, extend) {
  181. this.limit = 16;
  182. const param = {
  183. chName: this.getClassChName(tid), page: parseInt(pg), pageSize: this.limit
  184. };
  185. if (extend["label"] !== undefined) {
  186. param["label"] = extend["label"]
  187. }
  188. if (extend["country"] !== undefined) {
  189. param["country"] = extend["country"]
  190. }
  191. if (extend["time"] !== undefined) {
  192. const year = parseInt(extend["time"]);
  193. param["startTime"] = year;
  194. param["endTime"] = year;
  195. }
  196. const json = await this.post(this.apiUrl + '/v3/web/api/filter', JSON.stringify(param), {
  197. 'User-Agent': Utils.MOBILEUA, "Content-Type": 'application/json'
  198. }, "")
  199. const data = JSON.parse(json).data;
  200. this.vodList = await this.parseVodShortListFromJsonByCategory(data)
  201. this.count = Math.floor(data["total"] / this.limit);
  202. this.total = data.total
  203. }
  204. async setDetail(id) {
  205. const $ = await this.getHtml(this.siteUrl + '/vod/detail/' + id);
  206. const json = $('#__NEXT_DATA__')[0].children[0].data;
  207. const obj = JSON.parse(json).props["pageProps"];
  208. this.vodDetail = await this.parseVodDetailfromJson(obj)
  209. }
  210. async setSearch(wd, quick) {
  211. const limit = 20;
  212. const param = {
  213. word: wd, page: 1, pageSize: limit,
  214. };
  215. const json = await this.post(this.apiUrl + '/v3/web/api/search', JSON.stringify(param), this.getApiHeader(), "");
  216. const data = JSON.parse(json).data;
  217. this.vodList = await this.parseVodShortListFromJsonByCategory(data)
  218. }
  219. }
  220. let spider = new StarSpider()
  221. async function init(cfg) {
  222. await spider.init(cfg)
  223. }
  224. async function home(filter) {
  225. return await spider.home(filter)
  226. }
  227. async function homeVod() {
  228. return await spider.homeVod()
  229. }
  230. async function category(tid, pg, filter, extend) {
  231. return await spider.category(tid, pg, filter, extend)
  232. }
  233. async function detail(id) {
  234. return await spider.detail(id)
  235. }
  236. async function play(flag, id, flags) {
  237. return await spider.play(flag, id, flags)
  238. }
  239. async function search(wd, quick) {
  240. return await spider.search(wd, quick)
  241. }
  242. async function proxy(segments, headers) {
  243. return await spider.proxy(segments, headers)
  244. }
  245. export function __jsEvalReturn() {
  246. return {
  247. init: init,
  248. home: home,
  249. homeVod: homeVod,
  250. category: category,
  251. detail: detail,
  252. play: play,
  253. search: search,
  254. proxy: proxy
  255. };
  256. }
  257. export {spider}