当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript youtube-dl.getInfo函数代码示例

本文整理汇总了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)
  })
}
开发者ID:quoidautre,项目名称:PeerTube,代码行数:33,代码来源:import-videos.ts

示例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))
    })
  })
开发者ID:jiang263,项目名称:PeerTube,代码行数:8,代码来源:import-videos.ts

示例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);
				}
			});
		});
开发者ID:winneon,项目名称:djdiscord,代码行数:56,代码来源:Queue.ts


注:本文中的youtube-dl.getInfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。