kunyu77.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import './dayjs.min.js'
  2. import './uri.min.js';
  3. import './crypto-js.js'
  4. import _ from './underscore-esm-min.js'
  5. let key = 'kunyu77';
  6. let url = 'http://api.kunyu77.com';
  7. let agent = 'Dalvik/2.1.0 (Linux; U; Android 6.0; ZTE BA520 Build/MRA58K)';
  8. let deviceId = '';
  9. let timeOffset = 0;
  10. var charStr = 'abacdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789';
  11. function randIndex(min, max, i) {
  12. let index = Math.floor(Math.random() * (max - min + 1) + min),
  13. numStart = charStr.length - 10;
  14. if (i == 0 && index >= numStart) {
  15. index = randIndex(min, max, i);
  16. }
  17. return index;
  18. }
  19. function randomStr(len) {
  20. let min = 0, max = charStr.length - 1, _str = '';
  21. len = len || 15;
  22. for (var i = 0, index; i < len; i++) {
  23. index = randIndex(min, max, i);
  24. _str += charStr[index];
  25. }
  26. return _str;
  27. }
  28. function request(reqUrl) {
  29. let sj = dayjs().unix() - timeOffset;
  30. let uri = new Uri(reqUrl);
  31. uri.addQueryParam()
  32. uri.addQueryParam('pcode', '010110004')
  33. uri.addQueryParam('version', '2.0.4')
  34. uri.addQueryParam('devid', deviceId)
  35. uri.addQueryParam('package', 'com.sevenVideo.app.android')
  36. uri.addQueryParam('sys', 'android')
  37. uri.addQueryParam('sysver', '6.0')
  38. uri.addQueryParam('brand', 'ZTE')
  39. uri.addQueryParam('model', 'ZTE_BA520')
  40. uri.addQueryParam('sj', sj);
  41. let keys = [];
  42. for (var i = 0; i < uri.queryPairs.length; i++) {
  43. keys.push(uri.queryPairs[i][0]);
  44. }
  45. keys = _.sortBy(keys, function (name) { return name })
  46. let tkSrc = uri.path();
  47. for (let k of keys) {
  48. tkSrc += uri.getQueryParamValue(k);
  49. }
  50. tkSrc += sj;
  51. tkSrc += 'XSpeUFjJ';
  52. console.log(tkSrc);
  53. let tk = CryptoJS.MD5(tkSrc).toString().toLowerCase();
  54. console.log(tk);
  55. let header = {
  56. 'user-agent': agent,
  57. 't': sj,
  58. 'TK': tk,
  59. };
  60. let res = req(uri.toString(), {
  61. headers: header
  62. });
  63. let serverTime = res.headers.Date;
  64. let content = res.content;
  65. let serverTimeS = dayjs(serverTime).unix();
  66. timeOffset = dayjs().unix() - serverTimeS;
  67. // console.log(content);
  68. return content;
  69. }
  70. function init(ext) {
  71. var device = local.get(key, 'device');
  72. if (device.length == 0) {
  73. device = randomStr(32).toLowerCase();
  74. local.set(key, 'device', device);
  75. }
  76. deviceId = device;
  77. console.log(dayjs().unix());
  78. }
  79. function home(filter) {
  80. let data = JSON.parse(request(url + '/api.php/provide/filter')).data;
  81. let classes = [];
  82. for (const key in data) {
  83. classes.push({
  84. 'type_id': key,
  85. 'type_name': data[key][0].cat
  86. });
  87. }
  88. console.log(classes);
  89. return JSON.stringify({
  90. 'class': classes
  91. });
  92. }
  93. function homeVod(params) {
  94. let data = JSON.parse(request(url + '/api.php/provide/homeBlock?type_id=0')).data;
  95. let blocks = data.blocks;
  96. let videos = [];
  97. for (const block of blocks) {
  98. let name = block.block_name;
  99. if (name.indexOf('热播') >= 0)
  100. continue;
  101. let contents = block.contents;
  102. for (const content of contents) {
  103. videos.push({
  104. 'vod_id': content.id,
  105. 'vod_name': content.title,
  106. 'vod_pic': content.videoCover,
  107. 'vod_remarks': content.msg,
  108. })
  109. }
  110. }
  111. return JSON.stringify({
  112. 'list': videos
  113. });
  114. }
  115. function category(tid, pg, filter, extend) {
  116. let data = JSON.parse(request(url + '/api.php/provide/searchFilter?type_id=' + tid + '&pagenum=' + pg + '&pagesize=24')).data;
  117. let videos = []
  118. for (const vod of data.result) {
  119. videos.push({
  120. 'vod_id': vod.id,
  121. 'vod_name': vod.title,
  122. 'vod_pic': vod.videoCover,
  123. 'vod_remarks': vod.msg,
  124. });
  125. }
  126. return JSON.stringify({
  127. 'page': parseInt(data.page),
  128. 'pagecount': data.pagesize,
  129. 'limit': 24,
  130. 'total': data.total,
  131. 'list': videos,
  132. });
  133. }
  134. function detail(id) {
  135. let data = JSON.parse(request(url + '/api.php/provide/videoDetail?ids=' + id)).data;
  136. let vod = {
  137. 'vod_id': data.id,
  138. 'vod_name': data.videoName,
  139. 'vod_pic': data.videoCover,
  140. 'type_name': data.subCategory,
  141. 'vod_year': data.year,
  142. 'vod_area': data.area,
  143. 'vod_remarks': data.msg,
  144. 'vod_actor': data.actor,
  145. 'vod_director': data.director,
  146. 'vod_content': data.brief.trim(),
  147. }
  148. let episodes = JSON.parse(request(url + '/api.php/provide/videoPlaylist?ids=' + id)).data.episodes;
  149. let playlist = {};
  150. for (const episode of episodes) {
  151. let playurls = episode.playurls;
  152. for (const playurl of playurls) {
  153. let from = playurl.playfrom;
  154. if (!playlist.hasOwnProperty(from)) {
  155. playlist[from] = []
  156. }
  157. playlist[from].push(playurl.title.trim() + '$' + playurl.playurl);
  158. }
  159. }
  160. vod.vod_play_from = _.keys(playlist).join('$$$');
  161. let urls = _.values(playlist)
  162. let vod_play_url = []
  163. for (const urlist of urls) {
  164. vod_play_url.push(urlist.join('#'))
  165. }
  166. vod.vod_play_url = vod_play_url.join('$$$')
  167. return JSON.stringify({
  168. 'list': [vod]
  169. });
  170. }
  171. function play(flag, id, flags) {
  172. let data = JSON.parse(request(url + '/api.php/provide/parserUrl?url=' + id)).data;
  173. let playHeader = data.playHeader;
  174. let jxUrl = data.url;
  175. let jxData = JSON.parse(request(jxUrl));
  176. if (flags.indexOf(flag) >= 0) {
  177. return JSON.stringify({
  178. 'parse': 1,
  179. 'jx': 1,
  180. 'url': id
  181. });
  182. } else {
  183. return JSON.stringify({
  184. 'parse': 0,
  185. 'url': id
  186. });
  187. }
  188. }
  189. function search(wd, quick) {
  190. let data = JSON.parse(request(url + '/api.php/provide/searchVideo?searchName=' + wd)).data;
  191. let videos = [];
  192. for (const vod of data) {
  193. videos.push({
  194. 'vod_id': vod.id,
  195. 'vod_name': vod.videoName,
  196. 'vod_pic': vod.videoCover,
  197. 'vod_remarks': vod.msg,
  198. })
  199. }
  200. return JSON.stringify({
  201. 'list': videos
  202. });
  203. }
  204. __JS_SPIDER__ = {
  205. init: init,
  206. home: home,
  207. homeVod: homeVod,
  208. category: category,
  209. detail: detail,
  210. play: play,
  211. search: search
  212. }