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/'