API.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const axios = require("axios");
  2. const qs = require("qs");
  3. module.exports = (cookie) => {
  4. var headers = {
  5. 'cookie': cookie,
  6. 'content-type': 'application/x-www-form-urlencoded',
  7. 'referer': 'https://weibo.com/',
  8. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  9. }
  10. return {
  11. /**
  12. * 获取用户视频列表
  13. * @param {String} uid 用户ID
  14. * @param {String} cursor 下一个请求
  15. * @returns {Promise}
  16. */
  17. getWaterFallContent: async (uid, cursor=0) => {
  18. let url = "https://weibo.com/ajax/profile/getWaterFallContent"
  19. return axios.get(url, {
  20. headers: headers,
  21. params: {
  22. uid: uid,
  23. cursor: cursor
  24. }
  25. })
  26. },
  27. /**
  28. * 通过视频ID获取Video
  29. * @param {String} object_id 视频ID
  30. * @returns {Promise}
  31. */
  32. getVideoByURL: async (object_id) => {
  33. let url = "https://weibo.com/tv/api/component"
  34. return axios.post(url, data=`data={\"Component_Play_Playinfo\":{\"oid\":\"${object_id}\"}}`, {
  35. headers: headers,
  36. params: {
  37. page: `/tv/show/${object_id}`
  38. }
  39. })
  40. },
  41. /**
  42. * 获取用户视频标签
  43. * @param {String} uid 用户ID
  44. * @returns {Promise}
  45. */
  46. getVideoTab: async (uid) => {
  47. let url = "https://weibo.com/ajax/profile/getVideoTab"
  48. return axios.get(url, {
  49. headers: headers,
  50. params: {
  51. uid: uid
  52. }
  53. })
  54. },
  55. /**
  56. * 获取列表视频的详细信息
  57. * @param {String} cid Table列表中的id
  58. * @param {String} tab_code 排序 1: 最热、0: 默认
  59. * @param {String} cursor 下一页
  60. * @returns {Promise}
  61. */
  62. getCollectionList: async (cid, tab_code=0, cursor=0) => {
  63. let url = "https://weibo.com/ajax/profile/getCollectionList"
  64. var param = {}
  65. // 最热不能有cursor参数,还有一个 has_header = true/false -- 里面时最热默认的参数
  66. if (cursor == 0) {
  67. param = {
  68. cid: cid,
  69. tab_code: tab_code,
  70. }
  71. } else {
  72. param = {
  73. cid: cid,
  74. tab_code: tab_code,
  75. cursor: cursor
  76. }
  77. }
  78. return axios.get(url, {
  79. headers: headers,
  80. params: param
  81. })
  82. },
  83. /**
  84. * 获取点赞过的视频
  85. * @param {String} uid 用户UID
  86. * @param {String} cursor 下一页
  87. * @returns {Promise}
  88. */
  89. getLikeList: async (uid, cursor=0) => {
  90. let url = 'https://weibo.com/ajax/profile/getLikeList'
  91. return axios.get(url, {
  92. headers: headers,
  93. params: {
  94. uid: uid,
  95. cursor: cursor
  96. }
  97. })
  98. },
  99. /**
  100. * 通过UID获取用户信息
  101. * @param {String} uid 用户UID
  102. * @returns {Promise}
  103. */
  104. getInfoByUID: async (uid) => {
  105. let url = 'https://weibo.com/ajax/profile/info'
  106. return axios.get(url, {
  107. headers: headers,
  108. params: {
  109. 'uid': uid
  110. }
  111. })
  112. },
  113. /**
  114. * 通过UID获取用户IP归属地
  115. * @param {String} uid 用户UID
  116. * @returns {Promise}
  117. */
  118. getIPByUID: async (uid) => {
  119. let url = 'https://weibo.com/ajax/profile/detail'
  120. return axios.get(url, {
  121. headers: headers,
  122. params: {
  123. 'uid': uid
  124. }
  125. })
  126. }
  127. }
  128. }