當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。