nangua.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * @File : nangua.js
  3. * @Author : jade
  4. * @Date : 2024/3/18 10:54
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc : 南瓜影视
  8. */
  9. import {Crypto, jinja2, _} from "../lib/cat.js";
  10. import {Spider} from "./spider.js";
  11. import {VodDetail, VodShort} from "../lib/vod.js";
  12. function stripHtmlTag(src) {
  13. return src
  14. .replace(/<\/?[^>]+(>|$)/g, '')
  15. .replace(/&.{1,5};/g, '')
  16. .replace(/\s{2,}/g, ' ');
  17. }
  18. function formatPlayUrl(src, name) {
  19. return name
  20. .trim()
  21. .replaceAll(src, '')
  22. .replace(/<|>|《|》/g, '')
  23. .replace(/\$|#/g, ' ')
  24. .trim();
  25. }
  26. class NanGuaSpider extends Spider {
  27. constructor() {
  28. super();
  29. this.siteUrl = 'http://ys.changmengyun.com';
  30. }
  31. getName() {
  32. return "🎃┃南瓜影视┃🎃"
  33. }
  34. getAppName() {
  35. return "南瓜影视"
  36. }
  37. getJSName() {
  38. return "nangua"
  39. }
  40. getType() {
  41. return 3
  42. }
  43. async init(cfg) {
  44. await super.init(cfg);
  45. this.danmuStaus = true
  46. }
  47. getHeader() {
  48. let t = new Date().getTime().toString();
  49. return {
  50. 'version_name': '1.0.6',
  51. 'version_code': '6',
  52. 'package_name': 'com.app.nanguatv',
  53. 'sign': Crypto.MD5('c431ea542cee9679#uBFszdEM0oL0JRn@' + t).toString().toLowerCase(),
  54. 'imei': 'c431ea542cee9679',
  55. 'timeMillis': t,
  56. 'User-Agent': 'okhttp/4.6.0'
  57. }
  58. }
  59. async setClasses() {
  60. let data = JSON.parse(await this.fetch(this.siteUrl + '/api.php/provide/home_nav', null, this.getHeader()));
  61. for (const key in data) {
  62. if (data[key].name !== '精选') this.classes.push({
  63. type_id: data[key].id, type_name: data[key].name,
  64. });
  65. }
  66. }
  67. async setFilterObj() {
  68. this.filterObj = {
  69. "2": [{
  70. "key": "class",
  71. "name": "类型",
  72. "value": [{"n": "全部", "v": "类型"}, {"n": "国产剧", "v": "国产剧"}, {"n": "港台剧", "v": "港台剧"}]
  73. }, {
  74. "key": "area", "name": "地区", "value": [{"n": "全部", "v": "地区"}, {"n": "内地", "v": "内地"}, {
  75. "n": "香港地区", "v": "香港地区"
  76. }, {"n": "台湾地区", "v": "台湾地区"}]
  77. }, {
  78. "key": "year",
  79. "name": "年份",
  80. "value": [{"n": "全部", "v": "年份"}, {"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"}, {
  81. "n": "2021", "v": "2021"
  82. }, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"}, {
  83. "n": "2017", "v": "2017"
  84. }, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"}, {"n": "10年代", "v": "10年代"}, {
  85. "n": "00年代", "v": "00年代"
  86. }, {"n": "90年代", "v": "90年代"}, {"n": "80年代", "v": "80年代"}]
  87. }, {
  88. "key": "by", "name": "排序", "value": [{"n": "热播榜", "v": "热播榜"}, {"n": "好评榜", "v": "好评榜"}, {
  89. "n": "新上线", "v": "新上线"
  90. }]
  91. }], "1": [{
  92. "key": "class", "name": "类型", "value": [{"n": "全部", "v": "类型"}, {"n": "动作片", "v": "动作片"}, {
  93. "n": "喜剧片", "v": "喜剧片"
  94. }, {"n": "爱情片", "v": "爱情片"}, {"n": "科幻片", "v": "科幻片"}, {
  95. "n": "恐怖片", "v": "恐怖片"
  96. }, {"n": "剧情片", "v": "剧情片"}, {"n": "战争片", "v": "战争片"}, {"n": "惊悚片", "v": "惊悚片"}]
  97. }, {
  98. "key": "area", "name": "地区", "value": [{"n": "全部", "v": "地区"}, {"n": "华语", "v": "华语"}, {
  99. "n": "香港地区", "v": "香港地区"
  100. }, {"n": "美国", "v": "美国"}, {"n": "欧洲", "v": "欧洲"}, {"n": "韩国", "v": "韩国"}, {
  101. "n": "日本", "v": "日本"
  102. }, {"n": "台湾地区", "v": "台湾地区"}, {"n": "泰国", "v": "泰国"}, {
  103. "n": "台湾地区", "v": "台湾地区"
  104. }, {"n": "印度", "v": "印度"}, {"n": "其它", "v": "其它"}]
  105. }, {
  106. "key": "year",
  107. "name": "年份",
  108. "value": [{"n": "全部", "v": "年份"}, {"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"}, {
  109. "n": "2021", "v": "2021"
  110. }, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"}, {
  111. "n": "2017", "v": "2017"
  112. }, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"}, {"n": "10年代", "v": "10年代"}, {
  113. "n": "00年代", "v": "00年代"
  114. }, {"n": "90年代", "v": "90年代"}, {"n": "80年代", "v": "80年代"}]
  115. }, {
  116. "key": "by", "name": "排序", "value": [{"n": "热播榜", "v": "热播榜"}, {"n": "好评榜", "v": "好评榜"}, {
  117. "n": "新上线", "v": "新上线"
  118. }]
  119. }], "4": [{
  120. "key": "class", "name": "类型", "value": [{"n": "全部", "v": "类型"}, {"n": "国产漫", "v": "国产漫"}, {
  121. "n": "欧美漫", "v": "欧美漫"
  122. }, {"n": "日韩漫", "v": "日韩漫"}, {"n": "港台漫", "v": "港台漫"}]
  123. }, {
  124. "key": "area",
  125. "name": "地区",
  126. "value": [{"n": "全部", "v": "地区"}, {"n": "中国大陆", "v": "中国大陆"}, {
  127. "n": "日本", "v": "日本"
  128. }, {"n": "韩国", "v": "韩国"}, {"n": "欧美", "v": "欧美"}, {"n": "其它", "v": "其它"}]
  129. }, {
  130. "key": "year",
  131. "name": "年份",
  132. "value": [{"n": "全部", "v": "年份"}, {"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"}, {
  133. "n": "2021", "v": "2021"
  134. }, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"}, {
  135. "n": "2017", "v": "2017"
  136. }, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"}, {"n": "10年代", "v": "10年代"}, {
  137. "n": "00年代", "v": "00年代"
  138. }, {"n": "90年代", "v": "90年代"}, {"n": "80年代", "v": "80年代"}]
  139. }, {
  140. "key": "by", "name": "排序", "value": [{"n": "热播榜", "v": "热播榜"}, {"n": "新上线", "v": "新上线"}]
  141. }, {
  142. "key": "total",
  143. "name": "状态",
  144. "value": [{"n": "全部", "v": "状态"}, {"n": "连载", "v": "连载"}, {"n": "完结", "v": "完结"}]
  145. }], "3": [{
  146. "key": "class",
  147. "name": "类型",
  148. "value": [{"n": "全部", "v": "类型"}, {"n": "大陆", "v": "大陆"}, {"n": "港台", "v": "港台"}, {
  149. "n": "日韩", "v": "日韩"
  150. }, {"n": "欧美", "v": "欧美"}]
  151. }, {
  152. "key": "area",
  153. "name": "地区",
  154. "value": [{"n": "全部", "v": "地区"}, {"n": "内地", "v": "内地"}, {"n": "港台", "v": "港台"}, {
  155. "n": "日韩", "v": "日韩"
  156. }, {"n": "欧美", "v": "欧美"}, {"n": "其它", "v": "其它"}]
  157. }, {
  158. "key": "year",
  159. "name": "年份",
  160. "value": [{"n": "全部", "v": "年份"}, {"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"}, {
  161. "n": "2021", "v": "2021"
  162. }, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"}, {
  163. "n": "2017", "v": "2017"
  164. }, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"}, {"n": "10年代", "v": "10年代"}, {
  165. "n": "00年代", "v": "00年代"
  166. }, {"n": "90年代", "v": "90年代"}, {"n": "80年代", "v": "80年代"}]
  167. }, {
  168. "key": "by", "name": "排序", "value": [{"n": "热播榜", "v": "热播榜"}, {"n": "新上线", "v": "新上线"}]
  169. }], "46": [{
  170. "key": "class", "name": "类型", "value": [{"n": "全部", "v": "类型"}, {"n": "日韩剧", "v": "日韩剧"}, {
  171. "n": "欧美剧", "v": "欧美剧"
  172. }, {"n": "海外剧", "v": "海外剧"}]
  173. }, {
  174. "key": "area",
  175. "name": "地区",
  176. "value": [{"n": "全部", "v": "地区"}, {"n": "韩国", "v": "韩国"}, {"n": "美剧", "v": "美剧"}, {
  177. "n": "日本", "v": "日本"
  178. }, {"n": "泰国", "v": "泰国"}, {"n": "英国", "v": "英国"}, {"n": "新加坡", "v": "新加坡"}, {
  179. "n": "其他", "v": "其他"
  180. }]
  181. }, {
  182. "key": "year",
  183. "name": "年份",
  184. "value": [{"n": "全部", "v": "年份"}, {"n": "2024", "v": "2024"}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"}, {
  185. "n": "2021", "v": "2021"
  186. }, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"}, {
  187. "n": "2017", "v": "2017"
  188. }, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"}, {"n": "10年代", "v": "10年代"}, {
  189. "n": "00年代", "v": "00年代"
  190. }, {"n": "90年代", "v": "90年代"}, {"n": "80年代", "v": "80年代"}]
  191. }, {
  192. "key": "by", "name": "排序", "value": [{"n": "热播榜", "v": "热播榜"}, {"n": "好评榜", "v": "好评榜"}, {
  193. "n": "新上线", "v": "新上线"
  194. }]
  195. }]
  196. };
  197. }
  198. async parseVodShortListFromJSONByHome(obj){
  199. let vod_list = []
  200. for (const data of obj["video"]){
  201. let video_vod_list = await this.parseVodShortListFromJson(data["data"])
  202. vod_list.push(...video_vod_list)
  203. }
  204. return vod_list
  205. }
  206. async parseVodShortListFromJson(obj) {
  207. let vod_list = []
  208. for (const data of obj){
  209. let vodShort = new VodShort()
  210. vodShort.vod_id = data["id"]
  211. vodShort.vod_name = data["name"]
  212. vodShort.vod_pic = data["img"]
  213. vodShort.vod_remarks = data["remarks"]
  214. if (_.isEmpty(vodShort.vod_remarks)){
  215. vodShort.vod_remarks = data["msg"]
  216. }
  217. vod_list.push(vodShort)
  218. }
  219. return vod_list
  220. }
  221. async parseVodShortListFromJsonBySearch(obj) {
  222. let videos = [];
  223. obj.forEach(function (it) {
  224. videos.push({
  225. vod_id: it.id, vod_name: it["video_name"], vod_pic: it.img, vod_remarks: it["qingxidu"] + '/' + it.category,
  226. });
  227. });
  228. return videos
  229. }
  230. async parseVodDetailfromJson(obj) {
  231. let vodDetail = new VodDetail()
  232. vodDetail.vod_id = obj["id"]
  233. vodDetail.vod_name = obj["name"]
  234. vodDetail.vod_pic = obj["img"]
  235. vodDetail.type_name = obj["type"]
  236. vodDetail.vod_year = obj["year"]
  237. vodDetail.vod_content = stripHtmlTag(obj["info"])
  238. vodDetail.vod_remarks = '更新至: ' + obj["msg"] + ' / 评分: ' + obj["score"]
  239. let episodes = obj["player_info"];
  240. let playlist = {};
  241. episodes.forEach(function (it) {
  242. let playurls = it["video_info"];
  243. playurls.forEach(function (playurl) {
  244. let source = it.show;
  245. let t = formatPlayUrl(vodDetail.vod_name, playurl.name);
  246. if (t.length === 0) t = playurl.name.trim();
  247. if (!playlist.hasOwnProperty(source)) {
  248. playlist[source] = [];
  249. }
  250. playlist[source].push(t + '$' + playurl.url);
  251. });
  252. });
  253. vodDetail.vod_play_from = _.keys(playlist).join('$$$');
  254. let urls = _.values(playlist);
  255. let vod_play_url = [];
  256. urls.forEach(function (it) {
  257. vod_play_url.push(it.join('#'));
  258. });
  259. vodDetail.vod_play_url = vod_play_url.join('$$$');
  260. return vodDetail
  261. }
  262. async setHomeVod() {
  263. let data = JSON.parse(await this.fetch(this.siteUrl + '/api.php/provide/home_data?app=ylys&devices=android&imei=c431ea542cee9679&deviceModel=Subsystem%20for%20Android(TM)&deviceVersion=33&appVersionName=1.0.9&deviceScreen=427*250&appVersionCode=9&deviceBrand=Windows', null, this.getHeader()));
  264. this.homeVodList = await this.parseVodShortListFromJSONByHome(data)
  265. }
  266. async setCategory(tid, pg, filter, extend) {
  267. if (pg <= 0 || typeof (pg) == 'undefined') pg = 1;
  268. let reqUrl = this.siteUrl + '/api.php/provide/vod_list?app=ylys&id=' + tid + '&page=' + pg + '&imei=c431ea542cee9679&';
  269. reqUrl += jinja2('area={{ext.area}}&year={{ext.year}}&type={{ext.class}}&total={{ext.total}}&order={{ext.by}}', {ext: extend});
  270. let data = JSON.parse(await this.fetch(reqUrl, null, this.getHeader())).list;
  271. this.vodList = await this.parseVodShortListFromJson(data)
  272. let pgChk = JSON.parse(await this.fetch(this.siteUrl + '/api.php/provide/vod_list?app=ylys&id=' + tid + '&page=' + (parseInt(pg) + 1) + '&imei=c431ea542cee9679&', null, this.getHeader())).msg;
  273. this.count = (pgChk === 'ok') ? parseInt(pg) + 1 : parseInt(pg);
  274. this.limit = 20
  275. this.total = this.limit * this.count
  276. }
  277. async setDetail(id) {
  278. let data = JSON.parse(await this.fetch(this.siteUrl + '/api.php/provide/vod_detail?app=ylys&imei=c431ea542cee9679&id=' + id, null, this.getHeader())).data;
  279. this.vodDetail = await this.parseVodDetailfromJson(data)
  280. }
  281. async setSearch(wd, quick) {
  282. let data = JSON.parse(await this.fetch(this.siteUrl + '/api.php/provide/search_result_more?app=ylys&video_name=' + wd + '&pageSize=20&tid=0&imei=c431ea542cee9679&page=0', null, this.getHeader())).data;
  283. this.vodList = await this.parseVodShortListFromJsonBySearch(data)
  284. }
  285. async setPlay(flag, id, flags) {
  286. try {
  287. if (id.indexOf('m3u8') !== -1) {
  288. this.playUrl = id.split('url=')[1]
  289. } else if (id.indexOf(',') !== -1) {
  290. let mjurl = id.split(',')[1]
  291. let jData = JSON.parse(await this.fetch(mjurl, null, this.getHeader()));
  292. this.playUrl = jData["data"]["url"]
  293. } else {
  294. let jData = JSON.parse(await this.fetch(id, null, this.getHeader()));
  295. this.playUrl = jData["data"]["url"]
  296. }
  297. } catch (e) {
  298. await this.jadeLog.error("播放失败")
  299. }
  300. }
  301. }
  302. let spider = new NanGuaSpider()
  303. async function init(cfg) {
  304. await spider.init(cfg)
  305. }
  306. async function home(filter) {
  307. return await spider.home(filter)
  308. }
  309. async function homeVod() {
  310. return await spider.homeVod()
  311. }
  312. async function category(tid, pg, filter, extend) {
  313. return await spider.category(tid, pg, filter, extend)
  314. }
  315. async function detail(id) {
  316. return await spider.detail(id)
  317. }
  318. async function play(flag, id, flags) {
  319. return await spider.play(flag, id, flags)
  320. }
  321. async function search(wd, quick) {
  322. return await spider.search(wd, quick)
  323. }
  324. export function __jsEvalReturn() {
  325. return {
  326. init: init, home: home, homeVod: homeVod, category: category, detail: detail, play: play, search: search,
  327. };
  328. }
  329. export {spider}