star_open.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import { Crypto, load, _ } from 'assets://js/lib/cat.js';
  2. let key = 'star';
  3. let host = 'https://www.histar.tv';
  4. let apiHost = 'https://aws.ulivetv.net';
  5. let types = {};
  6. // let ver = '';
  7. let siteKey = '';
  8. let siteType = 0;
  9. const UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
  10. async function request(reqUrl, method, data) {
  11. const headers = {
  12. 'User-Agent': UA,
  13. };
  14. if (method == 'post') {
  15. headers['Content-Type'] = 'application/json';
  16. } else {
  17. headers['Cookie'] = 'userIP=127.0.0.1; aws-waf-token=';
  18. headers['Referer'] = host;
  19. }
  20. const res = await req(reqUrl, {
  21. method: method || 'get',
  22. headers: headers,
  23. data: data,
  24. });
  25. return res.content;
  26. }
  27. // cfg = {skey: siteKey, ext: extend}
  28. async function init(cfg) {
  29. siteKey = cfg.skey;
  30. siteType = cfg.stype;
  31. types = {
  32. 'movie': '电影',
  33. 'drama': '电视剧',
  34. 'animation': '动漫',
  35. 'variety': '综艺',
  36. 'documentary': '纪录片',
  37. };
  38. // ver = await getVer();
  39. }
  40. // async function getVer() {
  41. // const html = await request(host);
  42. // const $ = load(html);
  43. // const srcAttr = $('script[src*=\'buildManifest.js\']').attr('src');
  44. // return srcAttr.split('/')[3];
  45. // }
  46. async function home(filter) {
  47. const typeList = _.keys(types);
  48. const classes = _.map(typeList, (item) => {
  49. return { type_id: item, type_name: types[item] };
  50. });
  51. const filterConfig = {};
  52. const jsonData = JSON.stringify(typeList);
  53. for (const typeId of typeList) {
  54. const html = await request(host + '/' + typeId + '/all/all/all');
  55. const $ = load(html);
  56. const json = $('#__NEXT_DATA__')[0].children[0].data;
  57. const obj = JSON.parse(json).props.pageProps.filterCondition;
  58. const label = convertTypeData(obj, 'label', '类型');
  59. const country = convertTypeData(obj, 'country', '地区');
  60. const time = convertTypeData(obj, 'time', '年份');
  61. const filterArray = [label, country, time];
  62. filterConfig[typeId] = filterArray;
  63. };
  64. return JSON.stringify({
  65. class: classes,
  66. filters: filterConfig,
  67. });
  68. }
  69. function convertTypeData(typeData, key, name) {
  70. if (!typeData || !typeData[key] || typeData[key].length <= 2) {
  71. return null;
  72. }
  73. let valueList = typeData[key];
  74. if (key == 'time') {
  75. valueList = valueList.sort((a, b) => { return b - a;});
  76. valueList.pop();
  77. }
  78. const values = _.map(valueList, (item) => {
  79. let name;
  80. let value;
  81. if (item instanceof Array) {
  82. name = item[0];
  83. value = item[0];
  84. } else {
  85. name = item.toString();
  86. value = item.toString();
  87. }
  88. return {
  89. n: name,
  90. v: value,
  91. };
  92. });
  93. values.unshift({
  94. n: '全部',
  95. v: '',
  96. });
  97. const typeClass = {
  98. key: key,
  99. name: name,
  100. init: '',
  101. value: values,
  102. };
  103. return typeClass;
  104. }
  105. async function homeVod() {
  106. const html = await request(host);
  107. const $ = load(html);
  108. const json = $('#__NEXT_DATA__')[0].children[0].data;
  109. const obj = JSON.parse(json).props.pageProps.cards;
  110. const videos = [];
  111. _.each(obj, (cards) => {
  112. if (cards.name == '电视直播') return;
  113. _.each(cards.cards, (card) => {
  114. const v = {
  115. vod_id: card.id,
  116. vod_name: card.name,
  117. vod_pic: card.img,
  118. vod_remarks: card.countStr,
  119. };
  120. videos.push(v);
  121. });
  122. });
  123. return JSON.stringify({
  124. list: videos,
  125. });
  126. }
  127. async function category(tid, pg, filter, extend) {
  128. const limit = 16;
  129. const param = {
  130. chName: types[tid],
  131. page: pg,
  132. pageSize: limit,
  133. label: extend.label,
  134. country: extend.country,
  135. };
  136. if (extend.time) {
  137. const year = parseInt(extend.time);
  138. param.startTime = year;
  139. param.endTime = year;
  140. }
  141. const json = await request(apiHost + '/v3/web/api/filter', 'post', JSON.stringify(param));
  142. const data = JSON.parse(json).data;
  143. const videos = _.map(data.list, (card) => {
  144. return {
  145. vod_id: card.id,
  146. vod_name: card.name,
  147. vod_pic: card.img,
  148. vod_remarks: card.countStr,
  149. };
  150. });
  151. const page = parseInt(pg);
  152. const count = parseInt(data.total / limit);
  153. return JSON.stringify({
  154. page: page,
  155. pagecount: count,
  156. limit: limit,
  157. total: data.total,
  158. list: videos,
  159. });
  160. }
  161. async function detail(id) {
  162. const html = await request(host + '/vod/detail/' + id);
  163. const $ = load(html);
  164. const json = $('#__NEXT_DATA__')[0].children[0].data;
  165. const obj = JSON.parse(json).props.pageProps;
  166. const vObj = obj.pageData;
  167. const vodAtom = {
  168. vod_id: id,
  169. vod_name: vObj.name,
  170. vod_type: vObj.chname,
  171. vod_pic: vObj.picurl,
  172. vod_area: vObj.country,
  173. vod_lang: vObj.language,
  174. vod_remarks: vObj.countStr,
  175. vod_actor: vObj.actor,
  176. vod_director: vObj.director,
  177. vod_content: vObj.desc,
  178. }
  179. const playInfo = obj.videosGroup;
  180. const playVod = {};
  181. _.each(playInfo, (info) => {
  182. const sourceName = info.name;
  183. let playList = '';
  184. const videoInfo = info.videos;
  185. const vodItems = _.map(videoInfo, (epObj) => {
  186. const epName = epObj.epInfo;
  187. const playUrl = epObj.purl
  188. return epName + '$' + playUrl;
  189. });
  190. if (_.isEmpty(vodItems)) return;
  191. playList = vodItems.join('#');
  192. playVod[sourceName] = playList;
  193. });
  194. vodAtom.vod_play_from = _.keys(playVod).join('$$$');
  195. vodAtom.vod_play_url = _.values(playVod).join('$$$');
  196. return JSON.stringify({
  197. list: [vodAtom],
  198. });
  199. }
  200. async function play(flag, id, flags) {
  201. let playUrl = id;
  202. return JSON.stringify({
  203. parse: 0,
  204. url: playUrl,
  205. });
  206. }
  207. async function search(wd, quick, pg) {
  208. // const limit = 10;
  209. // const json = await request(host + '/_next/data/' + ver + '/search.json?word=' + encodeURIComponent(wd) + '&page=' + pg);
  210. // const data = JSON.parse(json).pageProps;
  211. // const videos = _.map(data.initList, (card) => {
  212. // return {
  213. // vod_id: card.id,
  214. // vod_name: card.name,
  215. // vod_pic: card.picurl,
  216. // vod_remarks: card.countStr,
  217. // };
  218. // });
  219. // const page = parseInt(pg);
  220. // const count = parseInt(data.total / limit);
  221. // return JSON.stringify({
  222. // page: page,
  223. // pagecount: count,
  224. // limit: limit,
  225. // total: data.total,
  226. // list: videos,
  227. // });
  228. const limit = 10;
  229. const param = {
  230. word: wd,
  231. page: pg,
  232. pageSize: limit,
  233. };
  234. const json = await request(apiHost + '/v3/web/api/search', 'post', JSON.stringify(param));
  235. const data = JSON.parse(json).data;
  236. const videos = _.map(data.list, (card) => {
  237. return {
  238. vod_id: card.id,
  239. vod_name: card.name,
  240. vod_pic: card.picurl,
  241. vod_remarks: card.countStr,
  242. };
  243. });
  244. const page = parseInt(pg);
  245. const count = parseInt(data.total / limit);
  246. return JSON.stringify({
  247. page: page,
  248. pagecount: count,
  249. limit: limit,
  250. total: data.total,
  251. list: videos,
  252. });
  253. }
  254. export function __jsEvalReturn() {
  255. return {
  256. init: init,
  257. home: home,
  258. homeVod: homeVod,
  259. category: category,
  260. detail: detail,
  261. play: play,
  262. search: search,
  263. };
  264. }