Skip to content

Commit

Permalink
新增获取dycookie,展示更多作品信息,图集于视频分类下载 #3 #5 #14 #15 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnserf-Seed committed Apr 9, 2023
1 parent be00e27 commit eb2fc0c
Showing 1 changed file with 82 additions and 44 deletions.
126 changes: 82 additions & 44 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down

0 comments on commit eb2fc0c

Please sign in to comment.