@dofiltra/youtube
Advanced tools
Comparing version 1.1.23 to 1.1.24
import type { TYtSearchVideoItem } from '@dofiltra/types'; | ||
export declare class ParserService { | ||
parseVideo(data: any): TYtSearchVideoItem | { | ||
id: { | ||
videoId: any; | ||
}; | ||
url: string; | ||
title: string; | ||
description: string; | ||
duration_raw: any; | ||
snippet: { | ||
url: string; | ||
duration: any; | ||
publishedAt: any; | ||
thumbnails: { | ||
id: any; | ||
url: any; | ||
default: any; | ||
high: any; | ||
height: any; | ||
width: any; | ||
}; | ||
title: string; | ||
views: any; | ||
}; | ||
views: any; | ||
channel: { | ||
isVerified: any; | ||
}; | ||
} | undefined; | ||
parseVideo(data: any): TYtSearchVideoItem | undefined; | ||
private getTitle; | ||
} |
export class ParserService { | ||
parseVideo(data) { | ||
if (!data) | ||
const renderer = data?.compactVideoRenderer || data?.videoRenderer || data?.videoWithContextRenderer; | ||
if (!renderer) { | ||
return undefined; | ||
let result = {}; | ||
} | ||
try { | ||
let title = ''; | ||
const renderer = data.compactVideoRenderer || data.videoRenderer; | ||
if (renderer) { | ||
title = renderer.title.runs[0].text; | ||
title = title.replace('\\\\', '\\'); | ||
try { | ||
title = decodeURIComponent(title); | ||
} | ||
catch (e) { | ||
// @ts-ignore | ||
} | ||
result = { | ||
...result, | ||
id: { | ||
videoId: renderer.videoId, | ||
}, | ||
const title = this.getTitle({ data }); | ||
const views = renderer?.viewCountText?.simpleText?.replace?.(/[^0-9]/g, '') || | ||
renderer?.shortViewCountText?.accessibility?.accessibilityData?.label?.replace(/[^0-9]/g, '') || | ||
0; | ||
const channel = { | ||
isVerified: renderer?.ownerBadges?.[0]?.metadataBadgeRenderer?.tooltip === 'Verified', | ||
}; | ||
const thumbnails = renderer.thumbnail?.thumbnails; | ||
const result = { | ||
id: { | ||
videoId: renderer.videoId, | ||
}, | ||
url: `https://www.youtube.com/watch?v=${renderer.videoId}`, | ||
title, | ||
description: renderer?.descriptionSnippet?.runs?.[0]?.text || '', | ||
duration_raw: renderer?.lengthText?.simpleText || renderer?.lengthText?.accessibility?.accessibilityData?.text, | ||
views, | ||
channel, | ||
snippet: { | ||
url: `https://www.youtube.com/watch?v=${renderer.videoId}`, | ||
title, | ||
description: renderer.descriptionSnippet && renderer.descriptionSnippet.runs[0] | ||
? renderer.descriptionSnippet.runs[0].text | ||
: '', | ||
duration_raw: renderer.lengthText ? renderer.lengthText.simpleText : null, | ||
snippet: { | ||
url: `https://www.youtube.com/watch?v=${renderer.videoId}`, | ||
duration: renderer.lengthText ? renderer.lengthText.simpleText : null, | ||
publishedAt: renderer.publishedTimeText ? renderer.publishedTimeText.simpleText : null, | ||
thumbnails: { | ||
id: renderer.videoId, | ||
url: renderer.thumbnail.thumbnails[renderer.thumbnail.thumbnails.length - 1].url, | ||
default: renderer.thumbnail.thumbnails[renderer.thumbnail.thumbnails.length - 1], | ||
high: renderer.thumbnail.thumbnails[renderer.thumbnail.thumbnails.length - 1], | ||
height: renderer.thumbnail.thumbnails[renderer.thumbnail.thumbnails.length - 1].height, | ||
width: renderer.thumbnail.thumbnails[renderer.thumbnail.thumbnails.length - 1].width, | ||
}, | ||
title, | ||
views: renderer.viewCountText && renderer.viewCountText.simpleText | ||
? renderer.viewCountText.simpleText.replace(/[^0-9]/g, '') | ||
: 0, | ||
duration: renderer?.lengthText?.simpleText || renderer.lengthText?.accessibility?.accessibilityData?.text, | ||
publishedAt: renderer?.publishedTimeText?.simpleText || renderer.publishedTimeText?.runs?.[0]?.text, | ||
thumbnails: { | ||
id: renderer.videoId, | ||
url: thumbnails?.[thumbnails?.length - 1]?.url, | ||
default: thumbnails?.[thumbnails?.length - 1], | ||
high: thumbnails[thumbnails.length - 1], | ||
height: thumbnails[thumbnails.length - 1].height, | ||
width: thumbnails[thumbnails.length - 1].width, | ||
}, | ||
views: renderer?.viewCountText?.simpleText?.replace?.(/[^0-9]/g, '') || 0, | ||
channel: { | ||
isVerified: renderer?.ownerBadges?.[0]?.metadataBadgeRenderer?.tooltip, | ||
}, | ||
}; | ||
return result; | ||
} | ||
if (data.videoWithContextRenderer) { | ||
if (data.videoWithContextRenderer.headline?.runs && data.videoWithContextRenderer.headline?.runs.length > 0) { | ||
title = data.videoWithContextRenderer.headline?.runs[0].text; | ||
} | ||
else { | ||
title = data.videoWithContextRenderer.headline?.accessibility?.accessibilityData?.label; | ||
} | ||
title = title.replace('\\\\', '\\'); | ||
try { | ||
title = decodeURIComponent(title); | ||
} | ||
catch (e) { | ||
// @ts-ignore | ||
} | ||
return { | ||
id: { | ||
videoId: data.videoWithContextRenderer.videoId, | ||
}, | ||
url: `https://www.youtube.com/watch?v=${data.videoWithContextRenderer.videoId}`, | ||
title, | ||
description: '', | ||
duration_raw: data.videoWithContextRenderer.lengthText?.accessibility?.accessibilityData?.text, | ||
snippet: { | ||
url: `https://www.youtube.com/watch?v=${data.videoWithContextRenderer.videoId}`, | ||
duration: data.videoWithContextRenderer.lengthText?.accessibility?.accessibilityData?.text, | ||
publishedAt: data.videoWithContextRenderer.publishedTimeText?.runs?.length > 0 | ||
? data.videoWithContextRenderer.publishedTimeText?.runs[0].text | ||
: null, | ||
thumbnails: { | ||
id: data.videoWithContextRenderer.videoId, | ||
url: data.videoWithContextRenderer.thumbnail.thumbnails[data.videoWithContextRenderer.thumbnail.thumbnails.length - 1].url, | ||
default: data.videoWithContextRenderer.thumbnail.thumbnails[data.videoWithContextRenderer.thumbnail.thumbnails.length - 1], | ||
high: data.videoWithContextRenderer.thumbnail.thumbnails[data.videoWithContextRenderer.thumbnail.thumbnails.length - 1], | ||
height: data.videoWithContextRenderer.thumbnail.thumbnails[data.videoWithContextRenderer.thumbnail.thumbnails.length - 1].height, | ||
width: data.videoWithContextRenderer.thumbnail.thumbnails[data.videoWithContextRenderer.thumbnail.thumbnails.length - 1].width, | ||
}, | ||
title, | ||
views: data.videoWithContextRenderer.shortViewCountText?.accessibility?.accessibilityData?.label?.replace(/[^0-9]/g, ''), | ||
}, | ||
views: data.videoWithContextRenderer?.shortViewCountText?.accessibility?.accessibilityData?.label?.replace(/[^0-9]/g, ''), | ||
channel: { | ||
isVerified: data.videoWithContextRenderer?.ownerBadges?.[0]?.metadataBadgeRenderer?.tooltip, | ||
}, | ||
}; | ||
} | ||
views, | ||
}, | ||
}; | ||
return result; | ||
} | ||
@@ -104,3 +49,24 @@ catch (e) { | ||
} | ||
getTitle({ data }) { | ||
let renderer = data?.compactVideoRenderer || data?.videoRenderer; | ||
let title = renderer?.title?.runs?.[0]?.text; | ||
if (!title) { | ||
renderer = data?.videoWithContextRenderer; | ||
if (renderer?.headline?.runs?.length > 0) { | ||
title = renderer?.headline?.runs?.[0]?.text; | ||
} | ||
else { | ||
title = renderer.headline?.accessibility?.accessibilityData?.label; | ||
} | ||
} | ||
try { | ||
title = (title || '').replace?.('\\\\', '\\') || ''; | ||
title = decodeURIComponent(title); | ||
} | ||
catch (e) { | ||
// @ts-ignore | ||
} | ||
return title || ''; | ||
} | ||
} | ||
//# sourceMappingURL=parser.service.js.map |
@@ -7,29 +7,2 @@ import { ProxyItem } from '@dofiltra/helpers'; | ||
sp?: string; | ||
}): Promise<(import("@dofiltra/types").TYtSearchVideoItem | { | ||
id: { | ||
videoId: any; | ||
}; | ||
url: string; | ||
title: string; | ||
description: string; | ||
duration_raw: any; | ||
snippet: { | ||
url: string; | ||
duration: any; | ||
publishedAt: any; | ||
thumbnails: { | ||
id: any; | ||
url: any; | ||
default: any; | ||
high: any; | ||
height: any; | ||
width: any; | ||
}; | ||
title: string; | ||
views: any; | ||
}; | ||
views: any; | ||
channel: { | ||
isVerified: any; | ||
}; | ||
})[]>; | ||
}): Promise<import("@dofiltra/types").TYtSearchVideoItem[]>; |
{ | ||
"name": "@dofiltra/youtube", | ||
"version": "1.1.23", | ||
"version": "1.1.24", | ||
"description": "Search videos on YouTube without API key", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30411
201