From 497b1aa61dad84ea9e748c69190dfbc4e75bed95 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Mon, 23 Aug 2021 13:05:40 +0530 Subject: [PATCH] added some new properties --- play-dl/YouTube/classes/Video.ts | 8 ++++---- play-dl/YouTube/utils/extractor.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/play-dl/YouTube/classes/Video.ts b/play-dl/YouTube/classes/Video.ts index bb1969e..0d51d22 100644 --- a/play-dl/YouTube/classes/Video.ts +++ b/play-dl/YouTube/classes/Video.ts @@ -6,8 +6,8 @@ interface VideoOptions { url? : string; title?: string; description?: string; - duration_formatted: string; - duration: number; + durationRaw: string; + durationInSec: number; uploadedAt?: string; views: number; thumbnail?: { @@ -84,8 +84,8 @@ export class Video { url: this.url, title: this.title, description: this.description, - duration: this.duration, - duration_formatted: this.durationFormatted, + durationInSec: this.duration, + durationRaw: this.durationFormatted, uploadedAt: this.uploadedAt, thumbnail: this.thumbnail?.toJSON(), channel: { diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 986e5d3..7d3e30e 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -23,7 +23,8 @@ export async function video_basic_info(url : string){ url : 'https://www.youtube.com/watch?v=' + vid.videoId, title : vid.title, description : vid.shortDescription, - duration : vid.lengthSeconds, + durationInSec : vid.lengthSeconds, + durationRaw : parseSeconds(vid.lengthSeconds), uploadedDate : microformat.publishDate, thumbnail : { width : vid.thumbnail.thumbnails[vid.thumbnail.thumbnails.length - 1].width, @@ -56,6 +57,18 @@ export async function video_basic_info(url : string){ } } +function parseSeconds(seconds : number): string { + let d = Number(seconds); + var h = Math.floor(d / 3600); + var m = Math.floor(d % 3600 / 60); + var s = Math.floor(d % 3600 % 60); + + var hDisplay = h > 0 ? (h < 10 ? `0${h}` : h) + ':' : ""; + var mDisplay = m > 0 ? (m < 10 ? `0${m}` : m) + ':' : "00:"; + var sDisplay = s > 0 ? (s < 10 ? `0${s}` : s) : "00"; + return hDisplay + mDisplay + sDisplay; +} + export async function video_info(url : string) { let data = await video_basic_info(url) if(data.LiveStreamData.isLive === true && data.LiveStreamData.hlsManifestUrl !== null){