nkvod_open.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import { Crypto, load, _ } from 'assets://js/lib/cat.js';
  2. let key = 'nkvod';
  3. let HOST = 'https://nkvod.pro';
  4. let parseMap = {};
  5. let siteKey = '';
  6. let siteType = 0;
  7. 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';
  8. async function request(reqUrl) {
  9. let res = await req(reqUrl, {
  10. method: 'get',
  11. headers: {
  12. 'User-Agent': UA,
  13. 'Referer': HOST
  14. },
  15. });
  16. return res.content;
  17. }
  18. // cfg = {skey: siteKey, ext: extend}
  19. async function init(cfg) {
  20. siteKey = cfg.skey;
  21. siteType = cfg.stype;
  22. await initParseMap();
  23. }
  24. async function initParseMap() {
  25. const date = new Date();
  26. const t = '' + date.getFullYear() + (date.getMonth() + 1) + date.getDate();
  27. const js = await request(HOST + '/static/js/playerconfig.js?t=' + t);
  28. try {
  29. const jsEval = js + '\nMacPlayerConfig';
  30. const playerList = eval(jsEval).player_list;
  31. const players = _.values(playerList);
  32. _.each(players, (item) => {
  33. if (!item.ps || item.ps == '0') return;
  34. if (_.isEmpty(item.parse)) return;
  35. parseMap[item.show] = item.parse;
  36. });
  37. } catch(e) {
  38. }
  39. }
  40. async function home(filter) {
  41. const classes = [{'type_id':'1','type_name':'电影'},{'type_id':'2','type_name':'电视剧'},{'type_id':'3','type_name':'综艺'},{'type_id':'4','type_name':'动漫'}];
  42. const filterObj = {
  43. '1':[{'key':'cateId','name':'类型','init':'1','value':[{'n':'全部','v':'1'},{'n':'动作片','v':'6'},{'n':'喜剧片','v':'7'},{'n':'爱情片','v':'8'},{'n':'科幻片','v':'9'},{'n':'恐怖片','v':'10'},{'n':'剧情片','v':'11'},{'n':'战争片','v':'12'}]},{'key':'year','name':'年代','init':'','value':[{'n':'全部','v':''},{'n':'2023','v':'2023'},{'n':'2022','v':'2022'},{'n':'2021','v':'2021'},{'n':'2020','v':'2020'},{'n':'2019','v':'2019'},{'n':'2018','v':'2018'},{'n':'2017','v':'2017'},{'n':'2016','v':'2016'},{'n':'2015','v':'2015'},{'n':'2014','v':'2014'},{'n':'2013','v':'2013'},{'n':'2012','v':'2012'},{'n':'2011','v':'2011'},{'n':'2010','v':'2010'}]},{'key':'by','name':'排序','value':[{'n':'时间','v':'time'},{'n':'人气','v':'hits'},{'n':'评分','v':'score'}]}],
  44. '2':[{'key':'cateId','name':'类型','init':'2','value':[{'n':'全部','v':'2'},{'n':'国产剧','v':'13'},{'n':'港台剧','v':'14'},{'n':'日韩剧','v':'15'},{'n':'欧美剧','v':'16'},{'n':'其他剧','v':'20'}]},{'key':'year','name':'年代','init':'','value':[{'n':'全部','v':''},{'n':'2023','v':'2023'},{'n':'2022','v':'2022'},{'n':'2021','v':'2021'},{'n':'2020','v':'2020'},{'n':'2019','v':'2019'},{'n':'2018','v':'2018'},{'n':'2017','v':'2017'},{'n':'2016','v':'2016'},{'n':'2015','v':'2015'},{'n':'2014','v':'2014'},{'n':'2013','v':'2013'},{'n':'2012','v':'2012'},{'n':'2011','v':'2011'},{'n':'2010','v':'2010'},{'n':'2009','v':'2009'},{'n':'2008','v':'2008'},{'n':'2007','v':'2007'},{'n':'2006','v':'2006'},{'n':'2005','v':'2005'},{'n':'2004','v':'2004'}]},{'key':'by','name':'排序','value':[{'n':'时间','v':'time'},{'n':'人气','v':'hits'},{'n':'评分','v':'score'}]}],
  45. '3':[{'key':'year','name':'年代','init':'','value':[{'n':'全部','v':''},{'n':'2023','v':'2023'},{'n':'2022','v':'2022'},{'n':'2021','v':'2021'},{'n':'2020','v':'2020'},{'n':'2019','v':'2019'},{'n':'2018','v':'2018'},{'n':'2017','v':'2017'},{'n':'2016','v':'2016'},{'n':'2015','v':'2015'},{'n':'2014','v':'2014'},{'n':'2013','v':'2013'},{'n':'2012','v':'2012'},{'n':'2011','v':'2011'},{'n':'2010','v':'2010'},{'n':'2009','v':'2009'},{'n':'2008','v':'2008'},{'n':'2007','v':'2007'},{'n':'2006','v':'2006'},{'n':'2005','v':'2005'},{'n':'2004','v':'2004'}]},{'key':'by','name':'排序','value':[{'n':'时间','v':'time'},{'n':'人气','v':'hits'},{'n':'评分','v':'score'}]}],
  46. '4':[{'key':'year','name':'年代','init':'','value':[{'n':'全部','v':''},{'n':'2023','v':'2023'},{'n':'2022','v':'2022'},{'n':'2021','v':'2021'},{'n':'2020','v':'2020'},{'n':'2019','v':'2019'},{'n':'2018','v':'2018'},{'n':'2017','v':'2017'},{'n':'2016','v':'2016'},{'n':'2015','v':'2015'},{'n':'2014','v':'2014'},{'n':'2013','v':'2013'},{'n':'2012','v':'2012'},{'n':'2011','v':'2011'},{'n':'2010','v':'2010'},{'n':'2009','v':'2009'},{'n':'2008','v':'2008'},{'n':'2007','v':'2007'},{'n':'2006','v':'2006'},{'n':'2005','v':'2005'},{'n':'2004','v':'2004'}]},{'key':'by','name':'排序','value':[{'n':'时间','v':'time'},{'n':'人气','v':'hits'},{'n':'评分','v':'score'}]}]
  47. };
  48. return JSON.stringify({
  49. class: classes,
  50. filters: filterObj,
  51. });
  52. }
  53. async function homeVod() {}
  54. async function category(tid, pg, filter, extend) {
  55. if (pg <= 0) pg = 1;
  56. const link = HOST + '/show/' + (extend.cateId || tid) + '--' + (extend.by || '') + '-' + (extend.class || '') + '--' + (extend.letter || '') + '---' + pg + '---' + (extend.year || '') + '.html';
  57. const html = await request(link);
  58. const $ = load(html);
  59. const items = $('a.module-item');
  60. const videos = _.map(items, (item) => {
  61. const $item = $(item);
  62. const a = $item;
  63. const img = $item.find('img:first');
  64. const remarks = $item.find('div.module-item-note').text().trim();
  65. return {
  66. vod_id: a.attr('href').replace(/.*?\/detail\/(.*).html/g, '$1'),
  67. vod_name: a.attr('title'),
  68. vod_pic: img.attr('data-original'),
  69. vod_remarks: remarks,
  70. };
  71. });
  72. const limit = 72;
  73. const hasMore = $('div#page > a:contains(下一页)').length > 0;
  74. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  75. return JSON.stringify({
  76. page: parseInt(pg),
  77. pagecount: pgCount,
  78. limit: limit,
  79. total: limit * pgCount,
  80. list: videos,
  81. });
  82. }
  83. async function detail(id) {
  84. const html = await request(HOST + '/detail/' + id + '.html');
  85. const $ = load(html);
  86. const vod = {
  87. vod_id: id,
  88. vod_name: $('h1:first').text().trim(),
  89. vod_type: $('.module-info-tag a:eq(2)').text().trim(),
  90. vod_year: $('.module-info-tag a:eq(0)').text().trim(),
  91. vod_area: $('.module-info-tag a:eq(1)').text().trim(),
  92. vod_actor: $('.module-info-item:contains(主演:)').text().trim().substring(3).replace(/\/$/, ''),
  93. vod_director: $('.module-info-item:contains(导演:)').text().trim().substring(3).replace(/\/$/, ''),
  94. vod_pic: $('.module-info-poster img:first').attr('data-original'),
  95. vod_remarks : $('.module-info-item:contains(备注:)').text(),
  96. vod_content: $('.module-info-introduction-content').text().trim(),
  97. };
  98. const playMap = {};
  99. const tabs = $('.module-tab .module-tab-item span');
  100. const playlists = $('.module-play-list');
  101. _.each(tabs, (tab, i) => {
  102. const $tab = $(tab);
  103. const from = $tab.text().trim();
  104. let list = playlists[i];
  105. list = $(list).find('a');
  106. _.each(list, (it) => {
  107. const $it = $(it);
  108. let title = $it.find('span').text();
  109. const playUrl = $it.attr('href');
  110. if (_.isEmpty(title)) title = $it.text();
  111. if (!playMap.hasOwnProperty(from)) {
  112. playMap[from] = [];
  113. }
  114. playMap[from].push(title + '$' + playUrl);
  115. });
  116. });
  117. vod.vod_play_from = _.keys(playMap).join('$$$');
  118. const urls = _.values(playMap);
  119. const vod_play_url = _.map(urls, (urlist) => {
  120. return urlist.join('#');
  121. });
  122. vod.vod_play_url = vod_play_url.join('$$$');
  123. return JSON.stringify({
  124. list: [vod],
  125. });
  126. }
  127. async function play(flag, id, flags) {
  128. const link = HOST + id;
  129. const html = await request(link);
  130. const $ = load(html);
  131. const js = JSON.parse($('script:contains(player_)').html().replace('var player_aaaa=',''));
  132. let playUrl = js.url;
  133. if (js.encrypt == 1) {
  134. playUrl = unescape(playUrl);
  135. } else if (js.encrypt == 2) {
  136. playUrl = unescape(base64Decode(playUrl));
  137. }
  138. const parseUrl = parseMap[flag];
  139. if (parseUrl) {
  140. const reqUrl = parseUrl + playUrl;
  141. const parseHtml = await request(reqUrl);
  142. const matches = parseHtml.match(/let ConFig = {([\w\W]*)},box/);
  143. if (!_.isEmpty(matches)) {
  144. const configJson = '{' + matches[1].trim() + '}';
  145. const config = JSON.parse(configJson);
  146. playUrl = decryptUrl(config);
  147. }
  148. }
  149. return JSON.stringify({
  150. parse: 0,
  151. url: playUrl,
  152. header: {
  153. 'User-Agent': UA,
  154. }
  155. });
  156. }
  157. function decryptUrl(jsConfig) {
  158. const key = Crypto.enc.Utf8.parse('2890' + jsConfig.config.uid + 'tB959C');
  159. const iv = Crypto.enc.Utf8.parse('GZ4JgN2BdSqVWJ1z');
  160. const mode = Crypto.mode.CBC;
  161. const padding = Crypto.pad.Pkcs7;
  162. const decrypted = Crypto.AES.decrypt(jsConfig.url, key, {
  163. iv: iv,
  164. mode: mode,
  165. padding: padding
  166. });
  167. const decryptedUrl = Crypto.enc.Utf8.stringify(decrypted);
  168. return decryptedUrl;
  169. }
  170. async function search(wd, quick) {
  171. const data = JSON.parse(await request(HOST + '/index.php/ajax/suggest?mid=1&limit=50&wd=' + wd)).list;
  172. const videos = _.map(data, (vod) => {
  173. return {
  174. vod_id: vod.id,
  175. vod_name: vod.name,
  176. vod_pic: vod.pic,
  177. vod_remarks: '',
  178. };
  179. });
  180. return JSON.stringify({
  181. list: videos,
  182. });
  183. }
  184. export function __jsEvalReturn() {
  185. return {
  186. init: init,
  187. home: home,
  188. homeVod: homeVod,
  189. category: category,
  190. detail: detail,
  191. play: play,
  192. search: search,
  193. };
  194. }