jable.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * @File : jable.js
  3. * @Author : jade
  4. * @Date : 2024/3/4 9:44
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {_, load} from '../lib/cat.js';
  10. import {VodDetail, VodShort} from "../lib/vod.js"
  11. import * as Utils from "../lib/utils.js";
  12. import {Spider} from "./spider.js";
  13. class JableTVSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://jable.tv"
  17. this.cookie = ""
  18. }
  19. getAppName() {
  20. return "Jable"
  21. }
  22. getName() {
  23. return "🔞┃Jable┃🔞"
  24. }
  25. getJSName() {
  26. return "jable"
  27. }
  28. getType() {
  29. return 3
  30. }
  31. getHeader() {
  32. // let header = super.getHeader()
  33. let header = {}
  34. header["User-Agent"] = "PostmanRuntime/7.36.3"
  35. header["Host"] = "jable.tv"
  36. // header["Postman-Token"] = "33290483-3c8d-413f-a160-0d3aea9e6f95"
  37. return header
  38. }
  39. async setClasses() {
  40. let $ = await this.getHtml(this.siteUrl)
  41. let navElements = $("[class=\"title-box\"]")
  42. let defaultTypeIdElements = $("div.row")
  43. for (const navElement of $(defaultTypeIdElements[0]).find("a")) {
  44. let type_name = $(navElement).text()
  45. let type_id = navElement.attribs.href
  46. if (type_id.indexOf(this.siteUrl) > -1) {
  47. this.classes.push(this.getTypeDic(type_name, type_id))
  48. }
  49. }
  50. navElements = navElements.slice(1, 9)
  51. defaultTypeIdElements = defaultTypeIdElements.slice(1, 9)
  52. for (let i = 0; i < navElements.length; i++) {
  53. let typeId = $(defaultTypeIdElements[i]).find("a")[0].attribs["href"]
  54. this.classes.push(this.getTypeDic("标签", typeId));
  55. break
  56. }
  57. }
  58. async getSortFilter($) {
  59. let sortElements = $("[class=\"sorting-nav\"]").find("a")
  60. let extend_dic = {"name": "排序", "key": "sort", "value": []}
  61. for (const sortElement of sortElements) {
  62. let typeId = sortElement.attribs["data-parameters"].split("sort_by:")[1]
  63. let typeName = $(sortElement).text()
  64. extend_dic["value"].push({"n": typeName, "v": typeId})
  65. }
  66. return extend_dic
  67. }
  68. async getFilter($, index, type_id, type_name) {
  69. let extend_list = []
  70. if (index < 4) {
  71. let extend_dic = {"name": type_name, "key": "type", "value": []}
  72. let type_seletc_list = ["div.img-box > a", "[class=\"horizontal-img-box ml-3 mb-3\"] > a", "", "sort"]
  73. let type_id_select_list = ["div.absolute-center > h4", "div.detail"]
  74. let default$ = await this.getHtml(type_id)
  75. for (const element of default$(type_seletc_list[index])) {
  76. let typeId = element.attribs["href"]
  77. let typeName = $($(element).find(type_id_select_list[index])).text().replaceAll("\t", "").replaceAll("\n", '').replaceAll(" ", "");
  78. extend_dic["value"].push({"n": typeName, "v": typeId})
  79. }
  80. if (extend_dic.value.length > 0) {
  81. extend_list.push(extend_dic)
  82. //排序
  83. let sortDetail$ = await this.getHtml(extend_dic["value"][0]["v"])
  84. let sort_extend_dic = await this.getSortFilter(sortDetail$)
  85. if (sort_extend_dic.value.length > 0) {
  86. extend_list.push(sort_extend_dic)
  87. }
  88. } else {
  89. //排序
  90. let sort_extend_dic = await this.getSortFilter(default$)
  91. if (sort_extend_dic.value.length > 0) {
  92. extend_list.push(sort_extend_dic)
  93. }
  94. }
  95. } else {
  96. let defaultTypeIdElements = $("div.row").slice(1, 9)
  97. let navElements = $("[class=\"title-box\"]").slice(1, 9)
  98. for (let i = 0; i < navElements.length; i++) {
  99. let extend_dic = {"name": $($(navElements[i]).find("h2")).text(), "key": "type", "value": []}
  100. for (const filterElement of $(defaultTypeIdElements[i]).find("a")) {
  101. let filter_type_id = filterElement.attribs.href
  102. if (filter_type_id.indexOf(this.siteUrl) > -1) {
  103. extend_dic["value"].push({"n": $(filterElement).text(), "v": filter_type_id})
  104. }
  105. }
  106. extend_list.push(extend_dic)
  107. }
  108. let sortDetail$ = await this.getHtml(type_id)
  109. let sort_extend_dic = await this.getSortFilter(sortDetail$)
  110. if (sort_extend_dic.value.length > 0) {
  111. extend_list.push(sort_extend_dic)
  112. }
  113. }
  114. return extend_list
  115. }
  116. async setFilterObj() {
  117. let $ = await this.getHtml(this.siteUrl)
  118. let classes = this.classes.slice(1)
  119. for (let i = 0; i < classes.length; i++) {
  120. let type_name = classes[i].type_name
  121. let type_id = classes[i].type_id
  122. // if (type_id.indexOf("models") > 1) {
  123. // type_id = `https://jable.tv/models/?mode=async&function=get_block&block_id=list_models_models_list&sort_by=total_videos&_=${new Date().getTime()}`
  124. // }
  125. let extend_list = await this.getFilter($, i, type_id, type_name)
  126. if (extend_list.length > 1 && i < 4) {
  127. type_id = extend_list[0]["value"][0]["v"]
  128. this.classes[i + 1] = this.getTypeDic(type_name, type_id)
  129. }
  130. this.filterObj[type_id] = extend_list
  131. }
  132. }
  133. async parseVodShortListFromDoc($) {
  134. let vod_list = []
  135. let vodElements = $("div.video-img-box")
  136. for (const element of vodElements) {
  137. let vodShort = new VodShort()
  138. vodShort.vod_pic = $(element).find("img").attr("data-src");
  139. let url = $(element).find("a").attr("href");
  140. vodShort.vod_id = url.split("/")[4];
  141. vodShort.vod_name = url.split("/")[4];
  142. let remarks_list = $($(element).find("[class=\"sub-title\"]")).text().split("\n")
  143. if (remarks_list.length > 1){
  144. vodShort.vod_remarks = remarks_list[1].replaceAll(" ", "").replaceAll("\t", "")
  145. }else{
  146. vodShort.vod_remarks = "精选"
  147. }
  148. if (!_.isEmpty(vodShort.vod_pic) && vodShort.vod_remarks !== "[限時優惠]只需1元即可無限下載"){
  149. vod_list.push(vodShort);
  150. }
  151. }
  152. return vod_list
  153. }
  154. async parseVodDetailFromDoc($) {
  155. let vodDetail = new VodDetail();
  156. let leftElement = $("[class=\"header-left\"]")
  157. vodDetail.vod_name = $($(leftElement).find("h4")).text();
  158. vodDetail.vod_pic = Utils.getStrByRegex(/<video poster="(.*?)" id=/, $.html())
  159. vodDetail.vod_year = $($("[class=\"inactive-color\"]")).text()
  160. let episodeName = $($("[class=\"header-right d-none d-md-block\"] > h6")).text().replaceAll("\n", "").replaceAll("●","")
  161. let vodItems = []
  162. let episodeUrl = Utils.getStrByRegex(/var hlsUrl = '(.*?)';/, $.html())
  163. vodItems.push(episodeName + "$" + episodeUrl)
  164. let vod_play_list = []
  165. vod_play_list.push(vodItems.join("#"))
  166. let vod_play_from_list = ["Jable"]
  167. vodDetail.vod_play_from = vod_play_from_list.join("$$$")
  168. vodDetail.vod_play_url = vod_play_list.join("$$$")
  169. return vodDetail
  170. }
  171. async setHomeVod() {
  172. let $ = await this.getHtml(this.siteUrl)
  173. this.homeVodList = await this.parseVodShortListFromDoc($)
  174. }
  175. async setDetail(id) {
  176. let $ = await this.getHtml(this.siteUrl + "/videos/" + id + "/")
  177. this.vodDetail = await this.parseVodDetailFromDoc($)
  178. }
  179. async setCategory(tid, pg, filter, extend) {
  180. let extend_type = extend["type"] ?? tid
  181. let sort_by = extend["sort"] ?? "video_viewed"
  182. this.limit = 24
  183. let cateUrl;
  184. this.total = 0
  185. this.count = 0
  186. if (tid.indexOf("latest-updates") > 1) {
  187. cateUrl = `https://jable.tv/latest-updates/?mode=async&function=get_block&block_id=list_videos_latest_videos_list&sort_by=post_date&from=${pg}&_=1709730132217`
  188. } else {
  189. cateUrl = extend_type + `/${pg}/?mode=async&function=get_block&block_id=list_videos_common_videos_list&sort_by=${sort_by}&_=${new Date().getTime()}`
  190. }
  191. let $ = await this.getHtml(cateUrl);
  192. this.vodList = await this.parseVodShortListFromDoc($)
  193. let page = $($("[class=\"page-item\"]").slice(-1)[0]).text()
  194. if (page.indexOf("最後") > -1) {
  195. } else {
  196. if (parseInt(page) === this.page || _.isEmpty(page)) {
  197. await this.jadeLog.debug("分类页面到底了")
  198. this.total = this.page
  199. this.count = this.page
  200. }
  201. }
  202. }
  203. async setSearch(wd, quick) {
  204. let searchUrl = this.siteUrl + `/search/${wd}/`
  205. let $ = await this.getHtml(searchUrl)
  206. this.vodList = await this.parseVodShortListFromDocByCategory($)
  207. }
  208. }
  209. let spider = new JableTVSpider()
  210. async function init(cfg) {
  211. await spider.init(cfg)
  212. }
  213. async function home(filter) {
  214. return await spider.home(filter)
  215. }
  216. async function homeVod() {
  217. return await spider.homeVod()
  218. }
  219. async function category(tid, pg, filter, extend) {
  220. return await spider.category(tid, pg, filter, extend)
  221. }
  222. async function detail(id) {
  223. return await spider.detail(id)
  224. }
  225. async function play(flag, id, flags) {
  226. return await spider.play(flag, id, flags)
  227. }
  228. async function search(wd, quick) {
  229. return await spider.search(wd, quick)
  230. }
  231. async function proxy(segments, headers) {
  232. return await spider.proxy(segments, headers)
  233. }
  234. export function __jsEvalReturn() {
  235. return {
  236. init: init,
  237. home: home,
  238. homeVod: homeVod,
  239. category: category,
  240. detail: detail,
  241. play: play,
  242. search: search,
  243. proxy: proxy
  244. };
  245. }
  246. export {spider}