quark_object.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * File: h:\PycharmProjects\Github\TVSpider\lib\quark_object.js
  3. * Project: h:\PycharmProjects\Github\TVSpider
  4. * Created Date: Monday, May 20th 2024, 5:26:45 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 {_} from "../lib/cat.js";
  15. import * as Utils from "./utils.js";
  16. class Item {
  17. constructor() {
  18. this.fileId = "";
  19. this.shareId = ""
  20. this.shareToken = "";
  21. this.shareFileToken = ""
  22. this.seriesId = ""
  23. this.name = "";
  24. this.type = "";
  25. this.formatType = "";
  26. this.size = "";
  27. this.parent = "";
  28. this.shareData = null;
  29. this.shareIndex = 0;
  30. this.lastUpdateAt = 0
  31. }
  32. static objectFrom(item_json, shareId,shareIndex) {
  33. let item = new Item();
  34. item.fileId = typeof item_json.fid == undefined ? "" : item_json.fid;
  35. item.shareId = shareId
  36. item.shareToken = typeof item_json.stoken == undefined ? "" : item_json.stoken;
  37. item.shareFileToken = typeof item_json.share_fid_token == undefined ? "" : item_json.share_fid_token;
  38. item.seriesId = typeof item_json.series_id == undefined? "":item_json.series_id
  39. item.name = typeof item_json.file_name == undefined ? "" : item_json.file_name;
  40. item.type = typeof item_json.obj_category == undefined ? "" : item_json.obj_category;
  41. item.formatType = typeof item_json.format_type == undefined? "" : item_json.format_type;
  42. item.size = typeof item_json.size == undefined ? "" : item_json.size;
  43. item.parent = typeof item_json.pdir_fid == undefined ? "" : item_json.pdir_fid;
  44. item.lastUpdateAt = typeof item_json.last_update_at == undefined ? "" : item_json.last_update_at
  45. item.shareIndex = shareIndex
  46. return item;
  47. }
  48. getFileExtension(){
  49. return this.name.split(".").slice(-1)[0]
  50. }
  51. getFileId() {
  52. return _.isEmpty(this.fileId) ? "" : this.fileId
  53. }
  54. getName() {
  55. return _.isEmpty(this.name) ? "" : this.name;
  56. }
  57. getParent() {
  58. return _.isEmpty(this.parent) ? "" : "[" + this.parent + "]";
  59. }
  60. getSize() {
  61. return this.size === 0 ? "" : "[" + Utils.getSize(this.size) + "]";
  62. }
  63. getShareIndex(){
  64. return this.shareIndex
  65. }
  66. getDisplayName(type_name) {
  67. let name = this.getName();
  68. if (type_name === "电视剧") {
  69. let replaceNameList = ["4k", "4K"]
  70. name = name.replaceAll("." + this.getFileExtension(), "")
  71. name = name.replaceAll(" ", "").replaceAll(" ", "")
  72. for (const replaceName of replaceNameList) {
  73. name = name.replaceAll(replaceName, "")
  74. }
  75. name = Utils.getStrByRegexDefault(/\.S01E(.*?)\./, name)
  76. const numbers = name.match(/\d+/g);
  77. if (!_.isEmpty(numbers) && numbers.length > 0) {
  78. name = numbers[0]
  79. }
  80. }
  81. return name + " " + this.getSize();
  82. }
  83. getEpisodeUrl(type_name){
  84. return this.getDisplayName(type_name) + "$" + this.getFileId() + "++" + this.shareFileToken + "++" + this.shareId + "++" + this.shareToken
  85. }
  86. }
  87. export {Item}