mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 12:31:17 +00:00
chore: clean up build steps
This commit is contained in:
32
src/parser/classes/misc/Author.js
Normal file
32
src/parser/classes/misc/Author.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import Parser from '../../index';
|
||||
import NavigatableText from './NavigatableText';
|
||||
import Thumbnail from './Thumbnail';
|
||||
import Constants from '../../../utils/Constants';
|
||||
|
||||
class Author {
|
||||
#nav_text;
|
||||
constructor(item, badges, thumbs) {
|
||||
this.#nav_text = new NavigatableText(item);
|
||||
this.id =
|
||||
this.#nav_text.runs?.[0].endpoint.browse?.id ||
|
||||
this.#nav_text.endpoint?.browse?.id || 'N/A';
|
||||
this.name = this.#nav_text.text || 'N/A';
|
||||
this.thumbnails = thumbs ? Thumbnail.fromResponse(thumbs) : [];
|
||||
this.endpoint = this.#nav_text.runs?.[0].endpoint || this.#nav_text.endpoint;
|
||||
this.badges = Array.isArray(badges) ? Parser.parseArray(badges) : [];
|
||||
this.is_verified = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
|
||||
this.is_verified_artist = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
|
||||
this.url =
|
||||
this.#nav_text.runs?.[0].endpoint.browse &&
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text.runs[0].endpoint.browse?.base_url || `/u/${this.#nav_text.runs[0].endpoint.browse?.id}`}` ||
|
||||
`${Constants.URLS.YT_BASE}${this.#nav_text.endpoint?.browse?.base_url || `/u/${this.#nav_text.endpoint?.browse?.id}`}` ||
|
||||
null;
|
||||
}
|
||||
/**
|
||||
* @type {Thumbnail | undefined}
|
||||
*/
|
||||
get best_thumbnail() {
|
||||
return this.thumbnails[0];
|
||||
}
|
||||
}
|
||||
export default Author;
|
||||
44
src/parser/classes/misc/Format.js
Normal file
44
src/parser/classes/misc/Format.js
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
class Format {
|
||||
constructor(data) {
|
||||
this.itag = data.itag;
|
||||
this.mime_type = data.mimeType;
|
||||
this.bitrate = data.bitrate;
|
||||
this.average_bitrate = data.averageBitrate;
|
||||
this.width = data.width || null;
|
||||
this.height = data.height || null;
|
||||
this.init_range = data.initRange ? {
|
||||
start: parseInt(data.initRange.start),
|
||||
end: parseInt(data.initRange.end)
|
||||
} : undefined;
|
||||
this.index_range = data.indexRange ? {
|
||||
start: parseInt(data.indexRange.start),
|
||||
end: parseInt(data.indexRange.end)
|
||||
} : undefined;
|
||||
this.last_modified = new Date(Math.floor(parseInt(data.lastModified) / 1000));
|
||||
this.content_length = parseInt(data.contentLength);
|
||||
this.quality = data.quality;
|
||||
this.quality_label = data.qualityLabel || null;
|
||||
this.fps = data.fps || null;
|
||||
this.url = data.url || null;
|
||||
this.cipher = data.cipher || null;
|
||||
this.signature_cipher = data.signatureCipher || null;
|
||||
this.audio_quality = data.audioQuality;
|
||||
this.approx_duration_ms = parseInt(data.approxDurationMs);
|
||||
this.audio_sample_rate = parseInt(data.audioSampleRate);
|
||||
this.audio_channels = data.audioChannels;
|
||||
this.loudness_db = data.loudnessDb;
|
||||
this.has_audio = !!data.audioBitrate || !!data.audioQuality;
|
||||
this.has_video = !!data.qualityLabel;
|
||||
}
|
||||
/**
|
||||
* Decipher the streaming url of the format.
|
||||
*
|
||||
* @param {import('../../../core/Player').default} player
|
||||
* @returns {string} Deciphered URL for downloading
|
||||
*/
|
||||
decipher(player) {
|
||||
return player.decipher(this.url, this.signature_cipher, this.cipher);
|
||||
}
|
||||
}
|
||||
export default Format;
|
||||
21
src/parser/classes/misc/NavigatableText.js
Normal file
21
src/parser/classes/misc/NavigatableText.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import Text from './Text';
|
||||
import NavigationEndpoint from '../NavigationEndpoint';
|
||||
class NavigatableText extends Text {
|
||||
static type = 'NavigatableText';
|
||||
endpoint;
|
||||
constructor(node) {
|
||||
super(node);
|
||||
// TODO: is this needed? Text now supports this itself
|
||||
this.endpoint =
|
||||
node.runs?.[0]?.navigationEndpoint ?
|
||||
new NavigationEndpoint(node.runs[0].navigationEndpoint) :
|
||||
node.navigationEndpoint ?
|
||||
new NavigationEndpoint(node.navigationEndpoint) :
|
||||
node.titleNavigationEndpoint ?
|
||||
new NavigationEndpoint(node.titleNavigationEndpoint) : null;
|
||||
}
|
||||
toJSON() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export default NavigatableText;
|
||||
10
src/parser/classes/misc/PlaylistAuthor.js
Normal file
10
src/parser/classes/misc/PlaylistAuthor.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Author from './Author';
|
||||
class PlaylistAuthor extends Author {
|
||||
constructor(data) {
|
||||
super(data);
|
||||
delete this.badges;
|
||||
delete this.is_verified;
|
||||
delete this.is_verified_artist;
|
||||
}
|
||||
}
|
||||
export default PlaylistAuthor;
|
||||
22
src/parser/classes/misc/Text.ts
Normal file
22
src/parser/classes/misc/Text.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import TextRun from './TextRun';
|
||||
import EmojiRun from '../EmojiRun';
|
||||
|
||||
class Text {
|
||||
text: string;
|
||||
runs;
|
||||
constructor(data: any) {
|
||||
if (data?.hasOwnProperty('runs') && Array.isArray(data.runs)) {
|
||||
this.runs = (data.runs as any[]).map((run: any) => run.emoji ?
|
||||
new EmojiRun(run) :
|
||||
new TextRun(run)
|
||||
);
|
||||
this.text = this.runs.map((run) => run.text).join('');
|
||||
} else {
|
||||
this.text = data?.simpleText || 'N/A';
|
||||
}
|
||||
}
|
||||
toString() {
|
||||
return this.text;
|
||||
}
|
||||
}
|
||||
export default Text;
|
||||
9
src/parser/classes/misc/TextRun.js
Normal file
9
src/parser/classes/misc/TextRun.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import NavigationEndpoint from '../NavigationEndpoint';
|
||||
|
||||
class TextRun {
|
||||
constructor(data) {
|
||||
this.text = data.text;
|
||||
this.endpoint = data.navigationEndpoint ? new NavigationEndpoint(data.navigationEndpoint) : undefined;
|
||||
}
|
||||
}
|
||||
export default TextRun;
|
||||
32
src/parser/classes/misc/Thumbnail.js
Normal file
32
src/parser/classes/misc/Thumbnail.js
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
class Thumbnail {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
url;
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
width;
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
height;
|
||||
constructor({ url, width, height }) {
|
||||
this.url = url;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
/**
|
||||
* Get thumbnails from response object
|
||||
*
|
||||
* @param {object} data - response object
|
||||
* @returns {Thumbnail[]} sorted array of thumbnails
|
||||
*/
|
||||
static fromResponse(data) {
|
||||
if (!data || !data.thumbnails)
|
||||
return;
|
||||
return data.thumbnails.map((x) => new Thumbnail(x)).sort((a, b) => b.width - a.width);
|
||||
}
|
||||
}
|
||||
export default Thumbnail;
|
||||
45
src/parser/classes/misc/VideoDetails.js
Normal file
45
src/parser/classes/misc/VideoDetails.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import Thumbnail from './Thumbnail';
|
||||
|
||||
class VideoDetails {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
id;
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
channel_id;
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
title;
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
keywords;
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
short_description;
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
author;
|
||||
constructor(data) {
|
||||
this.id = data.videoId;
|
||||
this.channel_id = data.channelId;
|
||||
this.title = data.title;
|
||||
this.duration = parseInt(data.lengthSeconds);
|
||||
this.keywords = data.keywords;
|
||||
this.is_owner_viewing = !!data.isOwnerViewing;
|
||||
this.short_description = data.shortDescription;
|
||||
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
|
||||
this.allow_ratings = !!data.allowRatings;
|
||||
this.view_count = parseInt(data.viewCount);
|
||||
this.author = data.author;
|
||||
this.is_private = !!data.isPrivate;
|
||||
this.is_live_content = !!data.isLiveContent;
|
||||
this.is_crawlable = !!data.isCrawlable;
|
||||
}
|
||||
}
|
||||
export default VideoDetails;
|
||||
Reference in New Issue
Block a user