simple_douyin_web.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. js:
  2. const douyin_cookie = "hiker://files/TyrantG/cookie/douyin.txt"
  3. // const slide_cookie = "hiker://files/TyrantG/cookie/douyin_slide.txt"
  4. const baseParse = _ => {
  5. let d = [], category, html
  6. let home_cookie = request(douyin_cookie)
  7. // let slide_d_cookie = request(slide_cookie)
  8. const empty = "hiker://empty"
  9. html = fetch("https://www.douyin.com", {headers:{"User-Agent": PC_UA, "cookie": home_cookie}, withHeaders: true})
  10. html = JSON.parse(html)
  11. // 首页cookie
  12. if (! home_cookie || ! home_cookie.match(/__ac_nonce/) || html.body.match(/<body><\/body>/)) {
  13. let cookie = html.headers["set-cookie"].join(';')
  14. writeFile(douyin_cookie, cookie.match(/__ac_nonce=(.*?);/)[0])
  15. }
  16. // 滑块验证
  17. if (html.body.match(/验证码/)) {
  18. d.push({
  19. title: '本地cookie失效, 请点击获取(需要过验证,15秒左右)',
  20. url: $(empty).lazyRule(_ => {
  21. const douyin_cookie = "hiker://files/TyrantG/cookie/douyin.txt"
  22. let current_cookie = request(douyin_cookie).match(/__ac_nonce=(.*?);/)[0]
  23. showLoading('自动验证中')
  24. let slide_cookie = fetch("http://student.tyrantg.com:8199/slide.php", {timeout: 30000})
  25. if(slide_cookie) writeFile(douyin_cookie, current_cookie+slide_cookie)
  26. hideLoading()
  27. refreshPage(true)
  28. return 'toast://验证成功'
  29. }),
  30. col_type: 'text_1'
  31. })
  32. } else {
  33. let current_page = MY_URL.split('##')[1].toString()
  34. let cate_select = getVar("tyrantgenesis.simple_douyin_web.cate_select", "")
  35. if (current_page === '1') {
  36. category = [
  37. {title: '全部', id: ''},
  38. {title: '娱乐', id: '300201'},
  39. {title: '知识', id: '300203'},
  40. {title: '二次元', id: '300206'},
  41. {title: '游戏', id: '300205'},
  42. {title: '美食', id: '300204'},
  43. {title: '体育', id: '300207'},
  44. {title: '时尚', id: '300208'},
  45. {title: '音乐', id: '300209'},
  46. ]
  47. category.forEach(cate => {
  48. d.push({
  49. title: cate_select === cate.id ? '‘‘’’<strong><font color="red">'+cate.title+'</font></strong>' : cate.title,
  50. url: $(empty).lazyRule(params => {
  51. putVar("tyrantgenesis.simple_douyin_web.cate_select", params.id)
  52. refreshPage(false)
  53. return "hiker://empty"
  54. }, {
  55. id: cate.id
  56. }),
  57. col_type: 'scroll_button',
  58. })
  59. })
  60. }
  61. // let not_sign_url = "https://www.douyin.com/aweme/v1/web/channel/feed/?device_platform=webapp&aid=6383&channel=channel_pc_web&tag_id="+cate_select+"&count=20&version_code=160100&version_name=16.1.0"
  62. let sign_url = fetch("http://douyin_signature.dev.tyrantg.com?type=feed&params="+cate_select)
  63. // let true_url = not_sign_url + "&_signature="+sign
  64. let data_json = fetch(sign_url, {
  65. headers: {
  66. "referer" : "https://www.douyin.com/",
  67. "cookie": home_cookie,
  68. "Accept": 'application/json, text/plain, */*',
  69. "User-Agent": PC_UA,
  70. "Accept-Language": 'zh-CN,zh;q=0.9',
  71. }
  72. })
  73. if (! data_json || data_json === 'Need Verifying') {
  74. d.push({
  75. title: 'signature 获取失败,待修复',
  76. col_type: "long_text",
  77. })
  78. } else {
  79. let list = JSON.parse(data_json).aweme_list
  80. if (list && list.length > 0) {
  81. list.forEach(item => {
  82. if (item.video && item.author) {
  83. d.push({
  84. title: item.desc,
  85. pic_url: item.video.cover.url_list[0],
  86. desc: item.author.nickname,
  87. url: $(empty).lazyRule(item => {
  88. return item.video.play_addr.url_list[0] + "#isVideo=true#"
  89. }, item),
  90. col_type: 'movie_2',
  91. })
  92. } else {
  93. //item.cell_room.rawdata.replace(/:([1-9]\d*),/g, ':"$1",')
  94. }
  95. })
  96. }
  97. }
  98. }
  99. setResult(d);
  100. }
  101. baseParse()