anfun_open.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Crypto, load, _, jinja2 } from './lib/cat.js';
  2. let key = 'anfun';
  3. let HOST = 'https://www.anfuns.cc';
  4. let siteKey = '';
  5. let siteType = 0;
  6. 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';
  7. async function request(reqUrl, agentSp) {
  8. let res = await req(reqUrl, {
  9. method: 'get',
  10. headers: {
  11. 'User-Agent': agentSp || UA,
  12. 'Referer': HOST
  13. },
  14. });
  15. return res.content;
  16. }
  17. // cfg = {skey: siteKey, ext: extend}
  18. async function init(cfg) {
  19. siteKey = cfg.skey;
  20. siteType = cfg.stype;
  21. }
  22. async function home(filter) {
  23. let classes = [{"type_id":1,"type_name":"新旧番剧"},{"type_id":2,"type_name":"蓝光无修"},{"type_id":3,"type_name":"动漫剧场"},{"type_id":4,"type_name":"欧美动漫"}];
  24. let filterObj = {
  25. "1":[{"key":"year","name":"年份","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"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},{"key":"by","name":"排序","value":[{"n":"最新","v":"/by/time"},{"n":"最热","v":"/by/hits"},{"n":"评分","v":"/by/score"}]}],
  26. "2":[{"key":"year","name":"年份","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"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},{"key":"by","name":"排序","value":[{"n":"最新","v":"/by/time"},{"n":"最热","v":"/by/hits"},{"n":"评分","v":"/by/score"}]}],
  27. "3":[{"key":"year","name":"年份","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"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},{"key":"by","name":"排序","value":[{"n":"最新","v":"/by/time"},{"n":"最热","v":"/by/hits"},{"n":"评分","v":"/by/score"}]}],
  28. "4":[{"key":"year","name":"年份","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"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},{"key":"by","name":"排序","value":[{"n":"最新","v":"/by/time"},{"n":"最热","v":"/by/hits"},{"n":"评分","v":"/by/score"}]}]
  29. };
  30. return JSON.stringify({
  31. class: classes,
  32. filters: filterObj,
  33. });
  34. }
  35. async function homeVod() {}
  36. async function category(tid, pg, filter, extend) {
  37. if (pg <= 0) pg = 1;
  38. const link = HOST + '/show/' + tid + '-' + (extend.class || '') + '--' + (extend.year || '') + (extend.by || '/by/time') + '/page/' + pg + '.html';//https://www.anfuns.cc/show/1---2023/by/hits/page/2.html
  39. const html = await request(link);
  40. const $ = load(html);
  41. const items = $('ul.hl-vod-list > li');
  42. let videos = _.map(items, (item) => {
  43. const it = $(item).find('a:first')[0];
  44. const remarks = $($(item).find('span.hl-lc-1')[0]).text().trim();
  45. return {
  46. vod_id: it.attribs.href.replace(/.*?\/anime\/(.*).html/g, '$1'),
  47. vod_name: it.attribs.title,
  48. vod_pic: it.attribs['data-original'],
  49. vod_remarks: remarks || '',
  50. };
  51. });
  52. const hasMore = $('ul.hl-page-wrap > li > a > span.hl-hidden-xs:contains(下一页)').length > 0;
  53. const pgCount = hasMore ? parseInt(pg) + 1 : parseInt(pg);
  54. return JSON.stringify({
  55. page: parseInt(pg),
  56. pagecount: pgCount,
  57. limit: 24,
  58. total: 24 * pgCount,
  59. list: videos,
  60. });
  61. }
  62. async function detail(id) {
  63. var html = await request( HOST + '/anime/' + id + '.html');
  64. var $ = load(html);
  65. var vod = {
  66. vod_id: id,
  67. vod_name: $('h1:first').text().trim(),
  68. vod_type: $('.stui-content__detail p:first a').text(),
  69. vod_actor: $('.stui-content__detail p:nth-child(3)').text().replace('主演:',''),
  70. vod_pic: $('.stui-content__thumb img:first').attr('data-original'),
  71. vod_remarks : $('.stui-content__detail p:nth-child(5)').text() || '',
  72. vod_content: $('span.detail-content').text().trim(),
  73. };
  74. var playMap = {};
  75. var tabs = $('ul.hl-from-list > li > span');
  76. var playlists = $('ul.hl-plays-list');
  77. _.each(tabs, (tab, i) => {
  78. var from = tab.children[0].data;
  79. var list = playlists[i];
  80. list = $(list).find('a');
  81. _.each(list, (it) => {
  82. var title = it.children[0].data;
  83. var playUrl = it.attribs.href.replace(/\/play\/(.*).html/g, '$1');
  84. if (!playMap.hasOwnProperty(from)) {
  85. playMap[from] = [];
  86. }
  87. playMap[from].push( title + '$' + playUrl);
  88. });
  89. });
  90. vod.vod_play_from = _.keys(playMap).join('$$$');
  91. var urls = _.values(playMap);
  92. var vod_play_url = _.map(urls, (urlist) => {
  93. return urlist.join('#');
  94. });
  95. vod.vod_play_url = vod_play_url.join('$$$');
  96. return JSON.stringify({
  97. list: [vod],
  98. });
  99. }
  100. async function play(flag, id, flags) {
  101. const link = HOST + '/play/' + id + '.html';
  102. const html = await request(link);
  103. const $ = load(html);
  104. const js = JSON.parse($('script:contains(player_)').html().replace('var player_aaaa=',''));
  105. const playurl = js.url;
  106. const playUrl = unescape(base64Decode(playurl));
  107. return JSON.stringify({
  108. parse: 0,
  109. url: playUrl,
  110. });
  111. }
  112. function base64Encode(text) {
  113. return Crypto.enc.Base64.stringify(Crypto.enc.Utf8.parse(text));
  114. }
  115. function base64Decode(text) {
  116. return Crypto.enc.Utf8.stringify(Crypto.enc.Base64.parse(text));
  117. }
  118. async function search(wd, quick) {
  119. let data = JSON.parse(await request(HOST + '/index.php/ajax/suggest?mid=1&wd=' + wd)).list;
  120. let videos = [];
  121. for (const vod of data) {
  122. videos.push({
  123. vod_id: vod.id,
  124. vod_name: vod.name,
  125. vod_pic: vod.pic,
  126. vod_remarks: '',
  127. });
  128. }
  129. return JSON.stringify({
  130. list: videos,
  131. });
  132. }
  133. export function __jsEvalReturn() {
  134. return {
  135. init: init,
  136. home: home,
  137. homeVod: homeVod,
  138. category: category,
  139. detail: detail,
  140. play: play,
  141. search: search,
  142. };
  143. }