mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-27 00:29:16 +00:00
feat(TextRun): add support for formatting (#254)
This commit is contained in:
@@ -3,9 +3,15 @@ import NavigationEndpoint from '../NavigationEndpoint';
|
||||
class TextRun {
|
||||
text: string;
|
||||
endpoint: NavigationEndpoint | undefined;
|
||||
bold: boolean;
|
||||
italics: boolean;
|
||||
strikethrough: boolean;
|
||||
|
||||
constructor(data: any) {
|
||||
this.text = data.text;
|
||||
this.bold = Boolean(data.bold);
|
||||
this.italics = Boolean(data.italics);
|
||||
this.strikethrough = Boolean(data.strikethrough);
|
||||
this.endpoint = data.navigationEndpoint ? new NavigationEndpoint(data.navigationEndpoint) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ export const VIDEOS = [
|
||||
{
|
||||
ID: 'I1qsF0WQy8c',
|
||||
QUERY: 'mkbhd',
|
||||
},
|
||||
{
|
||||
ID: 'OqiXFXlYFi8',
|
||||
QUERY: 'formatted comment text'
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from 'fs';
|
||||
import Innertube from '..';
|
||||
import { CHANNELS, VIDEOS } from './constants';
|
||||
import { streamToIterable } from '../src/utils/Utils';
|
||||
import TextRun from '../src/parser/classes/misc/TextRun';
|
||||
|
||||
describe('YouTube.js Tests', () => {
|
||||
let yt: Innertube;
|
||||
@@ -68,6 +69,19 @@ describe('YouTube.js Tests', () => {
|
||||
threads = await yt.getComments(VIDEOS[1].ID);
|
||||
expect(threads.contents.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should parse formatted comments', async () => {
|
||||
const threads = await yt.getComments(VIDEOS[3].ID);
|
||||
const authorComment = threads.contents.find(t => t.comment?.author_is_channel_owner)
|
||||
expect(authorComment).not.toBeUndefined();
|
||||
|
||||
expect(authorComment!.comment?.content.runs?.length).toBeGreaterThan(0)
|
||||
const runs = authorComment!.comment!.content.runs! as TextRun[]
|
||||
|
||||
expect(runs[0].bold).toBeTruthy()
|
||||
expect(runs[2].italics).toBeTruthy()
|
||||
expect(runs[4].strikethrough).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should retrieve next batch of comments', async () => {
|
||||
const next = await threads.getContinuation();
|
||||
|
||||
Reference in New Issue
Block a user