ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

Add `approxDurationMs` (and `width`/`height`) to `.toVideoFormats()` returned formats #36

Closed rklf closed 1 week ago

rklf commented 1 week ago

Describe the feature

Thanks for your work.

I'm wondering if you could add approxDurationMs (and width/height) to .toVideoFormats() returned formats to get video duration.

Deciphered format eg:

{
    itag: 137,
    url: '...',
    bitrate: 4334792,
    width: 1920,
    height: 1080,
    initRange: { start: '0', end: '741' },
    indexRange: { start: '742', end: '1181' },
    lastModified: '1676519733889895',
    contentLength: '70685780',
    quality: 'hd1080',
    fps: 25,
    qualityLabel: '1080p',
    projectionType: 'RECTANGULAR',
    averageBitrate: 3180462,
    approxDurationMs: '177800',
    _deciphered: true
},

After .toVideoFormats() eg:

{
  itag: 137,
  url: '...',
  mimeType: 'video/mp4; codecs="avc1.640028"',
  codec: { text: 'avc1.640028', video: 'avc1.640028', audio: null },
  quality: { text: 'hd1080', label: '1080p' },
  bitrate: 4334792,
  audioBitrate: NaN,
  contentLength: '70685780',
  container: 'mp4',
  hasVideo: true,
  hasAudio: false,
  isLive: false,
  isHLS: false,
  isDashMPD: false,
  sourceClientName: 'ios'
}
ybd-project commented 1 week ago

Thank you for sending your request. At this time, if you want to get the approxDurationMs property, please specify true as the second argument of toVideoFormats to get the original format data. Note that v6.0.9 will allow you to get the data without this need.

import { YtdlCore } from '@ybd-project/ytdl-core';

const FORMATS = [...],
    VIDEO_FORMATS = YtdlCore.toVideoFormats(FORMATS, true);

console.log(VIDEO_FORMATS[0].originalData.approxDurationMs);
rklf commented 1 week ago

Thanks