Skip to content

Commit

Permalink
chore: cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Sep 25, 2021
1 parent c521093 commit dfc2f9c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mc.listen()

- BREAKING: `emojiHandler` in `runsToString` now takes `YTEmojiRun` instead of `YTEmoji`
- Added `textHandler` option to `runsToString`
- BREAKING: Expand urls inside chat message (Thanks @stu43005)
- BREAKING: `runsToString` will expand truncated urls (Thanks @stu43005)

## v0.11.0

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export * from "./modules/chat";
export * from "./modules/context";
export { StreamPool } from "./pool";
export * from "./protobuf";
export { delay, runsToString, toVideoId } from "./utils";
export { delay, runsToString, toVideoId, endpointToUrl } from "./utils";
export * from "./yt";

export interface Metadata {
Expand Down
25 changes: 5 additions & 20 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import crossFetch from "cross-fetch";
import debug from "debug";
import { DC, DH, DO } from "./constants";
import { AbortError } from "./errors";
import {
YTEmojiRun,
YTRun,
YTTextRun,
YTUrlEndpointContainer,
YTWatchEndpointContainer,
} from "./yt/chat";
import { FluffyBrowseEndpoint, YTBrowseEndpointContainer } from "./yt/context";
import { YTEmojiRun, YTRun, YTTextRun } from "./yt/chat";
import { FluffyBrowseEndpoint } from "./yt/context";

export function ytFetch(input: string, init?: RequestInit) {
if (!input.startsWith("http")) {
Expand Down Expand Up @@ -60,19 +54,12 @@ function stripYtRedirection(url: string): string {
}

export function endpointToUrl(
navigationEndpoint: NonNullable<YTTextRun["navigationEndpoint"]>,
{
expandAll = false,
}: {
expandAll?: boolean;
} = {}
navigationEndpoint: NonNullable<YTTextRun["navigationEndpoint"]>
): string | undefined {
if ("urlEndpoint" in navigationEndpoint) {
return stripYtRedirection(navigationEndpoint.urlEndpoint.url);
}

if (!expandAll) return;

if ("watchEndpoint" in navigationEndpoint) {
const { watchEndpoint } = navigationEndpoint;

Expand Down Expand Up @@ -111,10 +98,8 @@ export function endpointToUrl(
}

export function textRunToPlainText(run: YTTextRun): string {
if (run.navigationEndpoint) {
return (
endpointToUrl(run.navigationEndpoint, { expandAll: false }) ?? run.text
);
if (run.navigationEndpoint && "urlEndpoint" in run.navigationEndpoint) {
return stripYtRedirection(run.navigationEndpoint.urlEndpoint.url);
}
return run.text;
}
Expand Down

0 comments on commit dfc2f9c

Please sign in to comment.