本文整理汇总了TypeScript中youtube-dl.getInfo函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getInfo函数的具体用法?TypeScript getInfo怎么用?TypeScript getInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getInfo函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: run
async function run () {
const res = await getClient(program['url'])
client = {
id: res.body.client_id,
secret: res.body.client_secret
}
const res2 = await login(program['url'], client, user)
accessToken = res2.body.access_token
const options = [ '-j', '--flat-playlist', '--playlist-reverse' ]
youtubeDL.getInfo(program['targetUrl'], options, processOptions, async (err, info) => {
if (err) throw err
let infoArray: any[]
// Normalize utf8 fields
if (Array.isArray(info) === true) {
infoArray = info.map(i => normalizeObject(i))
} else {
infoArray = [ normalizeObject(info) ]
}
console.log('Will download and upload %d videos.\n', infoArray.length)
for (const info of infoArray) {
await processVideo(info, program['language'])
}
// https://www.youtube.com/watch?v=2Upx39TBc1s
console.log('I\'m finished!')
process.exit(0)
})
}
示例2: async
return new Promise<any>(async (res, rej) => {
youtubeDL.getInfo(url, undefined, processOptions, async (err, videoInfo) => {
if (err) return rej(err)
const videoInfoWithUrl = Object.assign(videoInfo, { url })
return res(normalizeObject(videoInfoWithUrl))
})
})
示例3: Error
return new Promise<any>((resolve, reject) => {
ytdl.getInfo(link, (error, info) => {
if (error){
if (error.message.indexOf("ERROR: Unsupported URL") > -1){
reject(new Error("Invalid URL."));
} else {
reject(error);
}
} else if (info instanceof Array){
reject(new Error("Playlists not supported."));
} else {
// Credit to http://stackoverflow.com/a/9640417.
let split: string[] = info.duration.split(":");
let sec: number = 0;
let min: number = 1;
while (split.length > 0){
sec += min * parseInt(split.pop(), 10);
min *= 60;
}
let request: Request = new Request({
title: info.fulltitle,
link: url ? link : "https://www.youtube.com/watch?v=" + info.id,
requester: user.id ? user.id : user,
duration: sec,
shortTitle: info.title
});
if (that.list.length > 1 && that.list[that.list.length - 1].requester !== request.requester){
let i: number = that.list.length - 1;
while (true){
if (that.list[i - 1] && that.list[i].requester === that.list[i - 1].requester){
i--;
continue;
} else {
that.list.splice(i + 1, 0, request);
break;
}
}
} else {
that.list.push(request);
}
resolve({
request: request,
position: that.list.indexOf(request) + 1
});
setTimeout(() => {
that._checkQueue();
}, 1000);
}
});
});