feat(TextRun): add support for formatting (#254)

This commit is contained in:
absidue
2022-12-15 02:48:35 +01:00
committed by GitHub
parent 506834b253
commit 883a023624
3 changed files with 24 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -10,6 +10,10 @@ export const VIDEOS = [
{
ID: 'I1qsF0WQy8c',
QUERY: 'mkbhd',
},
{
ID: 'OqiXFXlYFi8',
QUERY: 'formatted comment text'
}
];

View File

@@ -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();