From eb2fc0c5aa845fc24ebd54f8f494725810a2392d Mon Sep 17 00:00:00 2001 From: JohnserfSeed Date: Sun, 9 Apr 2023 23:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96dycookie?= =?UTF-8?q?=EF=BC=8C=E5=B1=95=E7=A4=BA=E6=9B=B4=E5=A4=9A=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=9B=BE=E9=9B=86=E4=BA=8E=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=88=86=E7=B1=BB=E4=B8=8B=E8=BD=BD=20#3=20#5=20#14?= =?UTF-8?q?=20#15=20#17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #3 #5 #14 #15 #17 --- routes/api.js | 126 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/routes/api.js b/routes/api.js index 665a87d..8470300 100644 --- a/routes/api.js +++ b/routes/api.js @@ -30,64 +30,102 @@ var GetID = function (res,dyurl) { reject(error); }) } catch (error) { - console.log(error) + console.log('获取作品ID失败 ' + error) } }) } // 获取作品信息 -var GetInfo =function (res,item_ids) { +var GetInfo = function (res,item_ids,dycookie) { return new Promise((resolve, reject) => { - axios.get(`https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id=${item_ids}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`, { - headers: { - 'cookie': 'ttcid=fc21ed8a713b4a689f0a96f9f2bcd94833; tt_scid=cvwB6NvZMh82mfKdjm9zU4xUwtpzvswItKu9vSyL50Yd8gAoJaX1CoIaLBKRykxb36f9', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36' - } + const params_url = `aweme_id=${item_ids}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333` + let xb = getXB(params_url) + console.log(aweme_url + params_url + `&X-Bogus=${xb}`) + axios.get(aweme_url + params_url + `&X-Bogus=${xb}`, { + headers: { + 'cookie': `odin_tt=${dycookie['odin_tt']};sessionid_ss=${dycookie['sessionid_ss']};ttwid=${dycookie['ttwid']};passport_csrf_token=${dycookie['passport_csrf_token']};msToken=${dycookie['msToken']};`, + 'referer':'https://www.douyin.com/', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' + } + }) + .then(function (response) { + console.log('GetInfo ok') + let { + status_code + } = response.data + // console.log(response) + if (status_code === 0) { + // 无水印视频链接 + // let url = item_list.video.play_addr.url_list[0].replace( + // 'playwm', + // 'play' + // ) + // let url = response.data.aweme_detail.video.play_addr.url_list[2] + let uri = response.data.aweme_detail.video.play_addr.uri + let music = response.data.aweme_detail.music.play_url.uri + let m_title = response.data.aweme_detail.music.title + let unique_id = response.data.aweme_detail.author.unique_id + let video_id = response.data.aweme_detail.aweme_id + let aweme_type = response.data.aweme_detail.aweme_type + let nickname = response.data.aweme_detail.author.nickname + let userhome = 'https://www.douyin.com/user/' + response.data.aweme_detail.author.sec_uid + let newimages = Array(); + // 没有设置抖音号则获取短号 + if(unique_id == ''){ + unique_id = response.data.aweme_detail.author.short_id } - ).then(function (response) { - console.log('GetInfo ok') - // console.log("response", response.data) - let { - status_code - } = response.data - // console.log(response) - if (status_code === 0) { - // 无水印视频链接 - // let url = item_list.video.play_addr.url_list[0].replace( - // 'playwm', - // 'play' - // ) - // let url = response.data.aweme_detail.video.play_addr.url_list[2] - let uri = response.data.aweme_detail.video.play_addr.uri - // 转换成1080p - url = `http://aweme.snssdk.com/aweme/v1/play/?video_id=${uri}&ratio=1080p` - console.log('1080p ',url); - // 视频文案 - let desc = response.data.aweme_detail.desc; - // 文案过滤非法字符 - desc.replace(errwin, subwin); - - console.log('video play url ', url); - console.log('video desc ', desc); - var data = ({ - url: url, - desc: desc - }); - resolve(data); + if (aweme_type == '0'){ + var type = '视频' + var images = '' } else { - console.log(status_code); - reject(status_code); + var type = '图集' + var images = response.data.aweme_detail.images + for (var i in images){ + newimages.push(images[i].url_list[0]) + } } - }).catch(function (error) { - console.log(error) - res.render('error'); - reject(error) - }) + // 转换成1080p + url = `http://aweme.snssdk.com/aweme/v1/play/?video_id=${uri}&ratio=1080p` + // 视频文案过滤非法字符 + let desc = response.data.aweme_detail.desc.replaceAll(errwin, subwin); + + console.log('video play url ', url); + console.log('video desc ', desc); + var data = ({ + url: url, + desc: desc, + music: music, + m_title: m_title, + nickname: nickname, + unique_id: unique_id, + video_id: video_id, + userhome: userhome, + type:type, + images:newimages + }); + resolve(data); + } else { + console.log(status_code); + reject(status_code); + } + }).catch(function (error) { + console.log(error) + res.render('error'); + reject(error) + }) }) } /* GET api. */ router.get('/', async function(req, res, next) { + console.log(req.cookies['dycookie']) + if(req.cookies['dycookie'] == undefined){ + var data = ({ + work:false + }) + res.render('index', data); + return + } if (req.query.url == ''){ // 默认视频 req.query.url = 'https://v.douyin.com/NKyY6Ch/'