nivid_object.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * @File : nivid_object.js
  3. * @Author : jade
  4. * @Date : 2023/12/20 9:50
  5. * @Email : jadehh@1ive.com
  6. * @Software : Samples
  7. * @Desc :
  8. */
  9. import {Crypto} from "./cat.js";
  10. let DesKey = "diao.com"
  11. class ChannelResponse {
  12. // classes
  13. constructor() {
  14. this.channelMsg = ""
  15. this.channelStatus = 0
  16. this.channelList = []
  17. this.channelFilters = {}
  18. }
  19. fromJsonString(json_str, remove18ChannelCode = 0) {
  20. let json_dic = JSON.parse(json_str)
  21. this.channelMsg = json_dic.msg
  22. this.channelStatus = json_dic.status
  23. let channel_list = []
  24. for (const channel_info of json_dic.list) {
  25. let new_channel_info = new ChannelInfo()
  26. switch (remove18ChannelCode) {
  27. case 0:
  28. new_channel_info.fromJson(channel_info)
  29. channel_list.push(new_channel_info)
  30. break
  31. case 1:
  32. if (channel_info.channelName !== "午夜场" && channel_info.channelName !== "午夜直播") {
  33. new_channel_info.fromJson(channel_info)
  34. channel_list.push(new_channel_info)
  35. }
  36. break
  37. case 2:
  38. if (channel_info.channelName === "午夜场" || channel_info.channelName === "午夜直播") {
  39. new_channel_info.fromJson(channel_info)
  40. channel_list.push(new_channel_info)
  41. }
  42. break
  43. }
  44. }
  45. this.channelList = channel_list
  46. this.channelFilters = json_dic.filter
  47. }
  48. setChannelFilters(filter_str) {
  49. this.channelFilters = JSON.parse(filter_str)
  50. }
  51. getValues(typeList, name_key, id_key) {
  52. let values = []
  53. values.push({"n": "全部", "v": "0"})
  54. for (const obj of typeList) {
  55. values.push({"n": obj[name_key], "v": obj[id_key].toString()})
  56. }
  57. return values
  58. }
  59. getFilters() {
  60. let filters = {}
  61. for (const channel_info of this.channelList) {
  62. filters[channel_info.channelId] = []
  63. let sortMapList = this.channelFilters["sortsMap"][parseInt(channel_info.channelId)]
  64. let sortValues = this.getValues(sortMapList, "title", "id")
  65. filters[channel_info.channelId].push({"key": "1", "name": "排序", "value": sortValues})
  66. let typeMapList = this.channelFilters["typesMap"][parseInt(channel_info.channelId)]
  67. let typeValues = this.getValues(typeMapList, "showTypeName", "showTypeId")
  68. filters[channel_info.channelId].push({"key": "2", "name": "类型", "value": typeValues})
  69. let areaValues = this.getValues(this.channelFilters["regions"], "regionName", "regionId")
  70. filters[channel_info.channelId].push({"key": "3", "name": "地区", "value": areaValues})
  71. let langValues = this.getValues(this.channelFilters["langs"], "langName", "langId")
  72. filters[channel_info.channelId].push({"key": "4", "name": "语言", "value": langValues})
  73. let yearValues = this.getValues(this.channelFilters["yearRanges"], "name", "code")
  74. filters[channel_info.channelId].push({"key": "5", "name": "年份", "value": yearValues})
  75. }
  76. return filters
  77. }
  78. getChannelFilters() {
  79. return this.channelFilters
  80. }
  81. getChannelMsg() {
  82. return this.channelMsg
  83. }
  84. getChannelStatus() {
  85. return this.channelStatus
  86. }
  87. getChannelList() {
  88. return this.channelList
  89. }
  90. getClassList() {
  91. let classes = []
  92. for (const channel_info of this.channelList) {
  93. classes.push({"type_id": channel_info.channelId, "type_name": channel_info.channelName})
  94. }
  95. return classes
  96. }
  97. async save() {
  98. await local.set("niba", "niba_channel", this.toString());
  99. return this;
  100. }
  101. clear() {
  102. this.channelMsg = ""
  103. this.channelStatus = 0
  104. this.channelList = []
  105. }
  106. async clearCache() {
  107. this.clear()
  108. await local.set("niba", "niba_channel", "{}");
  109. }
  110. toString() {
  111. const params = {
  112. msg: this.getChannelMsg(),
  113. status: this.getChannelStatus(),
  114. list: this.getChannelList(),
  115. filter: this.getChannelFilters()
  116. };
  117. return JSON.stringify(params);
  118. }
  119. }
  120. async function getChannelCache() {
  121. return await local.get("niba", "niba_channel");
  122. }
  123. class ChannelInfo {
  124. constructor() {
  125. this.channelId = 0
  126. this.channelName = ""
  127. }
  128. fromJsonString(json_str) {
  129. let json_dic = JSON.parse(json_str)
  130. this.channelId = json_dic.channelId
  131. this.channelName = json_dic.channelName
  132. }
  133. fromJson(json) {
  134. this.channelId = json.channelId
  135. this.channelName = json.channelName
  136. }
  137. getChannelName() {
  138. return this.channelName
  139. }
  140. getChannelId() {
  141. return this.channelId
  142. }
  143. }
  144. function isNumeric(str) {
  145. return !isNaN(parseInt(str));
  146. }
  147. function getVod(video_dic_list, play_foramt_list, showIdCode) {
  148. let episode_list = [], episode_str_list = [];
  149. for (const video_dic of video_dic_list) {
  150. let video_name = ""
  151. if (isNumeric((video_dic['episodeName']))) {
  152. video_name = "第" + video_dic["episodeName"] + "集"
  153. } else {
  154. video_name = video_dic["episodeName"]
  155. }
  156. episode_list.push(video_name + "$" + video_dic["playIdCode"] + "@" + showIdCode);
  157. }
  158. for (let index = 0; index < play_foramt_list.length; index++) {
  159. episode_str_list.push(episode_list.join("#"));
  160. }
  161. return {
  162. vod_play_url: episode_str_list.join("$$$"),
  163. vod_play_from: play_foramt_list.map(item => item).join("$$$"),
  164. };
  165. }
  166. function getHeader() {
  167. return {
  168. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
  169. "Referer": "https://m.nivod.tv/",
  170. "Content-Type": "application/x-www-form-urlencoded"
  171. }
  172. }
  173. function md5(text) {
  174. return Crypto.MD5(text).toString()
  175. }
  176. //加密
  177. async function createSign(body = null) {
  178. let params = {
  179. "_ts": Date.now(), "app_version": "1.0",
  180. "platform": "3", "market_id": "web_nivod",
  181. "device_code": "web", "versioncode": 1,
  182. "oid": "8ca275aa5e12ba504b266d4c70d95d77a0c2eac5726198ea"
  183. }
  184. /**
  185. * __QUERY::_ts=1702973558399&app_version=1.0&device_code=web&market_id=web_nivod&oid=8ca275aa5e12ba504b266d4c70d95d77a0c2eac5726198ea&platform=3&versioncode=1&__BODY::__KEY::2x_Give_it_a_shot
  186. */
  187. let params_list = []
  188. for (const key of Object.keys(params).sort()) {
  189. params_list.push(`${key}=${params[key]}`)
  190. }
  191. let body_str = "&__BODY::"
  192. if (body !== null) {
  193. let body_list = []
  194. for (const key of Object.keys(body).sort()) {
  195. body_list.push(`${key}=${body[key]}`)
  196. }
  197. body_str = body_str + body_list.join("&") + "&"
  198. }
  199. let params_str = "__QUERY::" + params_list.join("&") + body_str + "__KEY::2x_Give_it_a_shot"
  200. let sign_code = md5(params_str)
  201. params_list.push(`sign=${sign_code}`)
  202. return "?" + params_list.join("&")
  203. }
  204. //解密
  205. function desDecrypt(content) {
  206. // 定义密钥
  207. const key = Crypto.enc.Utf8.parse(DesKey); // 密钥需要进行字节数转换
  208. /*
  209. const encrypted = Crypto.DES.encrypt(content, key, {
  210. mode: Crypto.mode.ECB, // 使用ECB模式
  211. padding: Crypto.pad.Pkcs7, // 使用Pkcs7填充
  212. }).ciphertext.toString();
  213. */
  214. return Crypto.DES.decrypt({ciphertext: Crypto.enc.Hex.parse(content)}, key, {
  215. mode: Crypto.mode.ECB,
  216. padding: Crypto.pad.Pkcs7,
  217. }).toString(Crypto.enc.Utf8);
  218. }
  219. export {getChannelCache, desDecrypt, createSign, ChannelResponse, getHeader, getVod};