quark.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * File: h:\PycharmProjects\Github\TVSpider\lib\quark.js
  3. * Project: h:\PycharmProjects\Github\TVSpider
  4. * Created Date: Monday, May 20th 2024, 4:54:26 pm
  5. * Author: jade
  6. * -----
  7. * Last Modified: Tue May 21 2024
  8. * Modified By: jade
  9. * -----
  10. * Copyright (c) 2024 samples
  11. * ------------------------------------
  12. * Javascript will save your soul!
  13. */
  14. import {JadeLogging} from "./log.js";
  15. import {Quark} from "./quark_api.js"
  16. const quarkName = "夸克云盘"
  17. const JadeLog = new JadeLogging(quarkName)
  18. const quark = new Quark()
  19. async function initQuark(cookie) {
  20. quark.initQuark(cookie)
  21. await JadeLog.info(`夸克云盘初始化完成,Cookie为:${cookie}`, true)
  22. }
  23. async function detailContentQuark(share_url_list, type_name = "电影") {
  24. try {
  25. let video_items = [], sub_items = []
  26. for (let i=0;i<share_url_list.length;i++){
  27. let share_url = share_url_list[i]
  28. await quark.getFilesByShareUrl(i+1,share_url,video_items,sub_items)
  29. }
  30. if (video_items.length > 0) {
  31. await JadeLog.info(`获取播放链接成功,分享链接为:${share_url_list.join("\t")}`)
  32. } else {
  33. await JadeLog.error(`获取播放链接失败,检查分享链接为:${share_url_list.join("\t")}`)
  34. }
  35. return {"video_items":video_items,"sub_items":sub_items}
  36. } catch (e) {
  37. await JadeLog.error('获取夸克视频失败,失败原因为:' + e.message + ' 行数为:' + e.lineNumber);
  38. }
  39. }
  40. function getQuarkPlayFormatList(){
  41. return quark.getPlayFormatList()
  42. }
  43. async function playContentQuark(flag, id, flags){
  44. let id_list = id.split("++")
  45. let shareId = id_list[2],stoken = id_list[3], fileId = id_list[0], fileToken = id_list[1]
  46. let playUrl = ""
  47. if (flag.indexOf("原画") > -1){
  48. playUrl = (await quark.getDownload(shareId, stoken, fileId, fileToken,true)).download_url
  49. }else{
  50. playUrl = await quark.getLiveTranscoding(shareId, stoken, fileId, fileToken,flag)
  51. }
  52. return playUrl
  53. }
  54. function getQuarkHeaders(){
  55. let headers = quark.getHeaders()
  56. delete headers["Host"]
  57. return headers
  58. }
  59. export {initQuark,detailContentQuark,playContentQuark,getQuarkPlayFormatList,quarkName,getQuarkHeaders}