mp4movie.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * @File : mp4movie.js
  3. * @Author : jade
  4. * @Date : 2024/2/19 9:41
  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 DyttSpider extends Spider {
  14. constructor() {
  15. super();
  16. this.siteUrl = "https://www.mp4us.com"
  17. this.apiUrl = "https://m.mp4us.com"
  18. this.dyttReconnectTimes = 0
  19. }
  20. async spiderInit(inReq=null) {
  21. if (inReq !== null){
  22. this.jsBase = await js2Proxy(inReq,"detail",this.getHeader());
  23. }else{
  24. this.jsBase = await js2Proxy(true, this.siteType, this.siteKey, 'detail/', this.getHeader());
  25. }
  26. }
  27. async init(cfg) {
  28. await super.init(cfg);
  29. await this.spiderInit(null)
  30. }
  31. getName() {
  32. return "🍚┃Mp4电影┃🍚"
  33. }
  34. getAppName() {
  35. return "Mp4电影"
  36. }
  37. getJSName() {
  38. return "mp4movie"
  39. }
  40. getType() {
  41. return 3
  42. }
  43. // getHeader() {
  44. // return {"User-Agent": Utils.CHROME, "Referer": this.siteUrl + "/","Connection":"keep-alive"};
  45. // }
  46. async getFilter() {
  47. let extend_list = []
  48. let $ = await this.getHtml()
  49. let suoyinElement = $("[class=\"nav navbar-nav\"]").find("li").slice(-1)[0]
  50. let souyinUrl = $(suoyinElement).find("a")[0].attribs.href
  51. let souyin$ = await this.getHtml(this.siteUrl + souyinUrl)
  52. let sortElements = souyin$("[class=\"sort-box\"]").find("[class=\"sort-list\"]").slice(1,-1)
  53. for (const sortElement of sortElements){
  54. let name = $($(sortElement).find("h5")).text().replace(":","")
  55. let extend_dic = {"key": name, "name":name, "value": []}
  56. for (const ele of $(sortElement).find("a")) {
  57. extend_dic["value"].push({"n": $(ele).text(), "v": ele.attribs.data.split("-")[1]})
  58. }
  59. extend_list.push(extend_dic)
  60. }
  61. return extend_list
  62. }
  63. // async setFilterObj() {
  64. // for (const type_dic of this.classes) {
  65. // let type_id = type_dic["type_id"]
  66. // if (type_id !== "最近更新") {
  67. // this.filterObj[type_id] = await this.getFilter()
  68. // }
  69. // }
  70. // }
  71. async setClasses() {
  72. let $ = await this.getHtml()
  73. let suoyinElement = $("[class=\"nav navbar-nav\"]").find("li").slice(-1)[0]
  74. let souyinUrl = $(suoyinElement).find("a")[0].attribs.href
  75. let souyin$ = await this.getHtml(this.siteUrl + souyinUrl)
  76. let sortElements = souyin$("[class=\"sort-box\"]").find("[class=\"sort-list\"]")
  77. let classElements = $(sortElements[0]).find("li")
  78. for (const classElement of classElements) {
  79. let type_name = $($(classElement).find("a")).text()
  80. let type_id = $(classElement).find("a")[0].attribs.data.replaceAll("id-", "")
  81. if (type_name !== "全部") {
  82. this.classes.push(this.getTypeDic(type_name, type_id))
  83. }
  84. }
  85. }
  86. async parseVodShortListFromDoc($) {
  87. let vod_list = []
  88. let vodElements = $("[class=\"index_today cclear\"]").find("a")
  89. for (const vodElement of vodElements){
  90. let vodShort = new VodShort();
  91. vodShort.vod_name = vodElement.attribs.title
  92. vodShort.vod_id = vodElement.attribs.href
  93. vodShort.vod_pic = this.jsBase + Utils.base64Encode(vodShort.vod_id)
  94. vod_list.push(vodShort)
  95. }
  96. return vod_list
  97. }
  98. getSearchHeader() {
  99. let headers = this.getHeader()
  100. headers["Cookie"] = "Hm_lvt_d8c8eecfb13fe991855f511a6e30c3d2=1708243467,1708325624,1708326536;Hm_lpvt_d8c8eecfb13fe991855f511a6e30c3d2;1708326536"
  101. return headers
  102. }
  103. async parseVodDetailFromDoc($) {
  104. let vodDetail = new VodDetail()
  105. let html = $.html()
  106. let detailRootElement = $("[class=\"article-header\"]")
  107. let detailElements = $(detailRootElement).find("p")
  108. let content = ""
  109. for (const detailElement of detailElements){
  110. content = content + $(detailElement).text() + "\n"
  111. }
  112. vodDetail.type_name = $($($(detailRootElement).find("[class=\"post-meta\"]")).find("span")[0]).text()
  113. vodDetail.vod_pic = $(detailRootElement).find("img")[0].attribs.src
  114. vodDetail.vod_name = Utils.getStrByRegex(/名称:(.*?)\n/,content)
  115. vodDetail.vod_actor = Utils.getStrByRegex(/主演:(.*?)\n/,content)
  116. vodDetail.vod_director = Utils.getStrByRegex(/导演:(.*?)\n/,content)
  117. vodDetail.vod_area = Utils.getStrByRegex(/地区:(.*?)\n/,content)
  118. vodDetail.vod_year = Utils.getStrByRegex(/年份:(.*?)\n/,content)
  119. vodDetail.vod_remarks = Utils.getStrByRegex(/更新:(.*?)\n/,content)
  120. let contentElement = $("[class=\"article-related info\"]").find("p")
  121. vodDetail.vod_content = $(contentElement).text()
  122. let downloadElements = $("[class=\"article-related download_url\"]")
  123. let vod_play_from_list = []
  124. let vod_play_list = []
  125. for (let i = 0; i < downloadElements.length; i++) {
  126. let playFormatElement = downloadElements[i]
  127. let format_name = $($(playFormatElement).find("h2")).text().replaceAll(vodDetail.vod_name,"")
  128. vod_play_from_list.push(format_name.replaceAll("下载","播放"))
  129. let vodItems = []
  130. for (const playUrlElement of $(downloadElements[i]).find("a")) {
  131. let episodeName = $(playUrlElement).text().replaceAll("磁力链下载","").replaceAll(".mp4","")
  132. let episodeUrl = playUrlElement.attribs.href
  133. vodItems.push(episodeName + "$" + episodeUrl)
  134. }
  135. vod_play_list.push(vodItems.join("#"))
  136. }
  137. vodDetail.vod_play_from = vod_play_from_list.join("$$$")
  138. vodDetail.vod_play_url = vod_play_list.join("$$$")
  139. return vodDetail
  140. }
  141. async parseVodShortListFromJson(obj) {
  142. let vod_list = []
  143. let $ = load(obj["ajaxtxt"])
  144. let vodElements = $($("ul")).find("li");
  145. for (const vodElement of vodElements){
  146. let vodShort = new VodShort()
  147. vodShort.vod_pic = $(vodElement).find("img")[0].attribs["data-original"]
  148. vodShort.vod_name = Utils.getStrByRegex(/《(.*?)》/,$(vodElement).find("img")[0].attribs.alt)
  149. vodShort.vod_id = $(vodElement).find("a")[0].attribs.href
  150. vodShort.vod_remarks = "评分:"+ $($(vodElement).find("[class=\"rate badge\"]")).text()
  151. vod_list.push(vodShort)
  152. }
  153. return vod_list
  154. }
  155. async parseVodShortListFromDocByCategory($) {
  156. let vod_list = []
  157. let vodElements = $($("[id=\"list_all\"]").find("ul")).find("li")
  158. for (const vodElement of vodElements){
  159. let vodShort = new VodShort()
  160. vodShort.vod_id = $(vodElement).find("a")[0].attribs.href
  161. vodShort.vod_name = Utils.getStrByRegex(/《(.*?)》/,$($($(vodElement).find("[class=\"text_info\"]")).find("a")[0]).text())
  162. vodShort.vod_pic = $(vodElement).find("img")[0].attribs["data-original"]
  163. vodShort.vod_remarks = $($(vodElement).find("[class=\"update_time\"]")).text()
  164. vod_list.push(vodShort)
  165. }
  166. return vod_list
  167. }
  168. async setHomeVod() {
  169. let $ = await this.getHtml();
  170. this.homeVodList = await this.parseVodShortListFromDoc($)
  171. }
  172. async setDetail(id) {
  173. let $ = await this.getHtml(this.siteUrl + id)
  174. this.vodDetail = await this.parseVodDetailFromDoc($)
  175. return this.vodDetail
  176. }
  177. async setCategory(tid, pg, filter, extend) {
  178. // let url = this.apiUrl + `/list-index-id-${tid}`
  179. // let area = extend["地区"] ?? ""
  180. // let year = extend["年代"] ?? ""
  181. // let tag = extend["标签"] ?? ""
  182. // if (parseInt(pg) > 1){
  183. // url = url + `-p-${pg}`
  184. // }
  185. // if (!_.isEmpty(area) && area !== "0"){
  186. // url = url + `-area-${area}`
  187. // }
  188. // if (!_.isEmpty(year) && year !== "0"){
  189. // url = url + `-year-${year}`
  190. // }
  191. // if (!_.isEmpty(tag) && tag !== "0"){
  192. // url = url + `-wd-${tag}`
  193. // }
  194. // let resp = await this.fetch(url + ".html",null,this.getHeader())
  195. // this.vodList = await this.parseVodShortListFromJson(JSON.parse(resp))
  196. let url = this.siteUrl + `/list/${tid}-${pg}.html`
  197. let $ = await this.getHtml(url)
  198. this.vodList = await this.parseVodShortListFromDocByCategory($)
  199. }
  200. async setSearch(wd, quick) {
  201. let url = this.siteUrl + "/search/"
  202. let params = {"wd":wd,"p":"1","t":"j/tNgwBS2e8O4x9TuIkYuQ=="}
  203. let html = await this.post(url,params,this.getSearchHeader())
  204. let $ = load(html)
  205. this.vodList = await this.parseVodShortListFromDocByCategory($)
  206. }
  207. }
  208. let spider = new DyttSpider()
  209. async function init(cfg) {
  210. await spider.init(cfg)
  211. }
  212. async function home(filter) {
  213. return await spider.home(filter)
  214. }
  215. async function homeVod() {
  216. return await spider.homeVod()
  217. }
  218. async function category(tid, pg, filter, extend) {
  219. return await spider.category(tid, pg, filter, extend)
  220. }
  221. async function detail(id) {
  222. return await spider.detail(id)
  223. }
  224. async function play(flag, id, flags) {
  225. return await spider.play(flag, id, flags)
  226. }
  227. async function search(wd, quick) {
  228. return await spider.search(wd, quick)
  229. }
  230. async function proxy(segments, headers) {
  231. return await spider.proxy(segments, headers)
  232. }
  233. export function __jsEvalReturn() {
  234. return {
  235. init: init,
  236. home: home,
  237. homeVod: homeVod,
  238. category: category,
  239. detail: detail,
  240. play: play,
  241. proxy: proxy,
  242. search: search,
  243. };
  244. }
  245. export {spider}