ggys_open.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import { Crypto, load, _ } from 'assets://js/lib/cat.js';
  2. const key = 'ggys';
  3. const HOST = 'https://ggys.me';
  4. const TYPE_MOVIE = 'movie';
  5. const TYPE_TVSHOW = 'tv-show';
  6. let siteKey = '';
  7. let siteType = 0;
  8. const UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
  9. async function request(reqUrl, method, data) {
  10. const res = await req(reqUrl, {
  11. method: method || 'get',
  12. headers: {
  13. 'User-Agent': UA,
  14. 'Referer': HOST,
  15. },
  16. data: data,
  17. postType: method === 'post' ? 'form' : '',
  18. });
  19. return res.content;
  20. }
  21. // cfg = {skey: siteKey, ext: extend}
  22. async function init(cfg) {
  23. siteKey = cfg.skey;
  24. siteType = cfg.stype;
  25. if (cfg.hasOwnProperty('ext')) {
  26. if (cfg.ext.hasOwnProperty('host')) {
  27. HOST = cfg.ext.host;
  28. }
  29. }
  30. }
  31. async function home(filter) {
  32. const classes = [{'type_id':'movies','type_name':'电影'},{'type_id':'tv-shows','type_name':'剧集'}];
  33. const filterObj = {
  34. 'movies':[{'key':'class','name':'类型','init':'','value':[{'n':'全部','v':''},{'n':'欧美电影','v':'tag/欧美电影'},{'n':'华语电影','v':'tag/华语电影'},{'n':'日韩电影','v':'tag/日韩电影'},{'n':'其他地区','v':'tag/其他地区'},{'n':'冒险','v':'genre/冒险'},{'n':'剧情','v':'genre/剧情'},{'n':'动作','v':'genre/动作'},{'n':'动画','v':'genre/动画'},{'n':'历史','v':'genre/历史'},{'n':'喜剧','v':'genre/喜剧'},{'n':'奇幻','v':'genre/奇幻'},{'n':'家庭','v':'genre/家庭'},{'n':'恐怖','v':'genre/恐怖'},{'n':'悬疑','v':'genre/悬疑'},{'n':'惊悚','v':'genre/惊悚'},{'n':'战争','v':'genre/战争'},{'n':'爱情','v':'genre/爱情'},{'n':'犯罪','v':'genre/犯罪'},{'n':'科幻','v':'genre/科幻'},{'n':'纪录','v':'genre/纪录'},{'n':'音乐','v':'genre/音乐'}]}],
  35. 'tv-shows':[{'key':'class','name':'类型','init':'','value':[{'n':'全部','v':''},{'n':'欧美剧','v':'tag/欧美剧'},{'n':'日韩剧','v':'tag/日韩剧'},{'n':'国产剧','v':'tag/国产剧'},{'n':'其他地区','v':'tag/其他地区'},{'n':'剧情','v':'genre/剧情'},{'n':'动作','v':'genre/动作'},{'n':'动画','v':'genre/动画'},{'n':'喜剧','v':'genre/喜剧'},{'n':'家庭','v':'genre/家庭'},{'n':'悬疑','v':'genre/悬疑'},{'n':'犯罪','v':'genre/犯罪'},{'n':'科幻','v':'genre/科幻'},{'n':'西部','v':'genre/西部'}]}],
  36. };
  37. return JSON.stringify({
  38. class: classes,
  39. filters: filterObj,
  40. });
  41. }
  42. async function homeVod() {}
  43. async function category(tid, pg, filter, extend) {
  44. if (pg <= 0) pg = 1;
  45. let path = '';
  46. const prefixMap = {
  47. 'movies': TYPE_MOVIE,
  48. 'tv-shows': TYPE_TVSHOW,
  49. }
  50. const prefix = prefixMap[tid];
  51. if (extend.class) {
  52. path = '/' + prefix + '-' + extend.class;
  53. } else {
  54. path = '/' + tid;
  55. }
  56. let page = '';
  57. if (pg > 1) {
  58. page = 'page/' + pg + '/';
  59. }
  60. const link = HOST + path + '/' + page;
  61. const html = await request(link);
  62. const $ = load(html);
  63. const videos = [];
  64. parseVideoList($, prefix, false, videos);
  65. const limit = 20;
  66. const hasMore = $('.page-numbers a.next').length > 0;
  67. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  68. return JSON.stringify({
  69. page: parseInt(pg),
  70. pagecount: pgCount,
  71. limit: limit,
  72. total: limit * pgCount,
  73. list: videos,
  74. });
  75. }
  76. function parseVideoList($, prefix, imgSrc, videos) {
  77. const items = $('.' + prefix);
  78. _.each(items, (item) => {
  79. const $item = $(item);
  80. const title = $item.find('.' + prefix + '__title:first').text();
  81. const url = $item.find('.' + prefix + '__actions a:first').attr('href');
  82. const imgAttr = imgSrc ? 'src' : 'data-lazy-src';
  83. const image = $item.find('.' + prefix + '__poster img:first').attr(imgAttr);
  84. const remarks = $item.find('.' + prefix + '__meta span:last').text();
  85. if (!url) return;
  86. const videoItem = {
  87. vod_id: decodeURIComponent(url.replace(/.*\/\/.*\/(.*\/.*)\//g, '$1')),
  88. vod_name: title,
  89. vod_pic: image,
  90. vod_remarks: remarks,
  91. };
  92. videos.push(videoItem);
  93. });
  94. }
  95. async function detail(id) {
  96. const isMovieType = id.startsWith(TYPE_MOVIE);
  97. const html = await request(HOST + '/' + id + '/');
  98. const $ = load(html);
  99. const prefix = isMovieType ? TYPE_MOVIE : TYPE_TVSHOW;
  100. const vod = {
  101. vod_id: id,
  102. vod_name: $('.' + prefix + '_title').text(),
  103. vod_actor: $('.' + prefix + '-casts').text().trim().substring(3).replace(/\s+\/\s+/g, '/'),
  104. vod_pic: $('.' + prefix + '__poster img:first').attr('data-lazy-src'),
  105. vod_remarks: $('.' + prefix + '__meta span:last').text(),
  106. };
  107. if (isMovieType) {
  108. vod.vod_type = $('.' + prefix + '__meta span:last').text();
  109. vod.vod_year = $('.' + prefix + '__meta span:first').text();
  110. vod.vod_content = $('.movie__description').text();
  111. } else {
  112. vod.vod_type = $('.' + prefix + '__meta span:first').text();
  113. vod.vod_content = $('.tv-show__info--body').text();
  114. }
  115. const from = 'ggys';
  116. const playMap = {};
  117. if (isMovieType) {
  118. const playId = $('.ggys-video-player').attr('data-source-id');
  119. const playCfg = playId + '@' + TYPE_MOVIE;
  120. playMap[from] = [ '全$' + playCfg ];
  121. } else {
  122. const tabs = $('.tv_show__season-tabs-wrap .nav-item');
  123. const episodes = $('.episodes');
  124. _.each(tabs, (tab, i) => {
  125. const titlePrefix = $(tab).text().trim();
  126. const episodeList = $(episodes[i]).find('.episode__body');
  127. _.each(episodeList, (episode) => {
  128. const $episode = $(episode);
  129. const title = titlePrefix + ' ' + $episode.text().trim();
  130. const url = $episode.find('a').attr('href');
  131. const playCfg = url + '@' + TYPE_TVSHOW;
  132. if (!playMap.hasOwnProperty(from)) {
  133. playMap[from] = [];
  134. }
  135. playMap[from].push(title + '$' + playCfg);
  136. });
  137. });
  138. }
  139. vod.vod_play_from = _.keys(playMap).join('$$$');
  140. const urls = _.values(playMap);
  141. const vod_play_url = _.map(urls, (urlist) => {
  142. return urlist.join('#');
  143. });
  144. vod.vod_play_url = vod_play_url.join('$$$');
  145. return JSON.stringify({
  146. list: [vod],
  147. });
  148. }
  149. async function play(flag, id, flags) {
  150. const playCfg = id.split('@');
  151. const playType = playCfg[1];
  152. let playId = playCfg[0];
  153. let playUrl;
  154. if (playType == TYPE_TVSHOW) {
  155. const html = await request(playId);
  156. const $ = load(html);
  157. playId = $('.ggys-video-player').attr('data-source-id');
  158. }
  159. const param = {
  160. video_id: playId,
  161. };
  162. const resp = await request(HOST + '/wp-json/get_addr/v1/get_video_url', 'post', param);
  163. playUrl = JSON.parse(resp).video_url;
  164. const headers = {
  165. 'User-Agent': UA,
  166. 'Referer': HOST,
  167. };
  168. return JSON.stringify({
  169. parse: 0,
  170. url: playUrl,
  171. header: headers,
  172. });
  173. }
  174. async function search(wd, quick, pg) {
  175. let page = '';
  176. if (pg > 1) {
  177. page = '/page/' + pg;
  178. }
  179. const url = HOST + '/search/' + wd + page + '/?post_type=';
  180. const videos = [];
  181. let html = await request(url + 'movie');
  182. let $ = load(html);
  183. parseVideoList($, TYPE_MOVIE, true, videos);
  184. const hasMoreMovie = $('.page-numbers a.next').length > 0;
  185. html = await request(url + 'tv_show');
  186. $ = load(html);
  187. parseVideoList($, TYPE_TVSHOW, true, videos);
  188. const hasMoreTVShow = $('.page-numbers a.next').length > 0;
  189. const limit = 40;
  190. const hasMore = hasMoreMovie || hasMoreTVShow;
  191. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  192. return JSON.stringify({
  193. page: parseInt(pg),
  194. pagecount: pgCount,
  195. limit: limit,
  196. total: limit * pgCount,
  197. list: videos,
  198. });
  199. }
  200. export function __jsEvalReturn() {
  201. return {
  202. init: init,
  203. home: home,
  204. homeVod: homeVod,
  205. category: category,
  206. detail: detail,
  207. play: play,
  208. search: search,
  209. };
  210. }