diff --git a/README.md b/README.md
index 97537d972..123958eb9 100644
--- a/README.md
+++ b/README.md
@@ -254,6 +254,7 @@ const yt = await Innertube.create({
* [.getPlaylist(id)](#getplaylist)
* [.getStreamingData(video_id, options)](#getstreamingdata)
* [.download(video_id, options?)](#download)
+ * [.resolveURL(url)](#resolveurl)
* [.call(endpoint, args?)](#call)
@@ -563,6 +564,16 @@ Downloads a given video.
See [`./examples/download`](https://github.com/LuanRT/YouTube.js/blob/main/examples/download) for examples.
+
+### resolveURL(url)
+Resolves a given url.
+
+**Returns**: `Promise.`
+
+| Param | Type | Description |
+| --- | --- | --- |
+| url | `string` | Url to resolve |
+
### call(endpoint, args?)
Utility to call navigation endpoints.
diff --git a/src/Innertube.ts b/src/Innertube.ts
index 0256415e8..cf892ae00 100644
--- a/src/Innertube.ts
+++ b/src/Innertube.ts
@@ -263,6 +263,15 @@ class Innertube {
return info.download(options);
}
+ /**
+ * Resolves the given URL.
+ * @param url - The URL.
+ */
+ async resolveURL(url: string): Promise {
+ const response = await this.actions.execute('/navigation/resolve_url', { url, parse: true });
+ return response.endpoint as NavigationEndpoint;
+ }
+
/**
* Utility method to call an endpoint without having to use {@link Actions}.
* @param endpoint -The endpoint to call.
diff --git a/src/parser/index.ts b/src/parser/index.ts
index edb225bb0..a5b5d64b3 100644
--- a/src/parser/index.ts
+++ b/src/parser/index.ts
@@ -148,6 +148,7 @@ export default class Parser {
hls_manifest_url: data.streamingData?.hlsManifestUrl as string || null
} : undefined,
current_video_endpoint: data.currentVideoEndpoint ? new NavigationEndpoint(data.currentVideoEndpoint) : null,
+ endpoint: data.endpoint ? new NavigationEndpoint(data.endpoint) : null,
captions: Parser.parseItem(data.captions),
video_details: data.videoDetails ? new VideoDetails(data.videoDetails) : undefined,
annotations: Parser.parseArray(data.annotations),
diff --git a/test/constants.ts b/test/constants.ts
index 9b15794f3..083ccc034 100644
--- a/test/constants.ts
+++ b/test/constants.ts
@@ -19,7 +19,7 @@ export const VIDEOS = [
export const CHANNELS = [
{
- ID: 'UC_x5XG1OV2P6uZZ5FSM9Ttw',
+ ID: 'UCXuqSBlHAE6Xw-yeJA0Tunw',
NAME: 'Linus Tech Tips'
}
];
\ No newline at end of file
diff --git a/test/main.test.ts b/test/main.test.ts
index 270fde4c2..de2130f95 100644
--- a/test/main.test.ts
+++ b/test/main.test.ts
@@ -116,6 +116,11 @@ describe('YouTube.js Tests', () => {
});
describe('General', () => {
+ it('should resolve a URL', async () => {
+ const url = await yt.resolveURL('https://www.youtube.com/@linustechtips');
+ expect(url.payload.browseId).toBe(CHANNELS[0].ID);
+ });
+
it('should retrieve playlist', async () => {
const playlist = await yt.getPlaylist('PLLw0AzOz95FU7w2juhPECP9NyGhbZmz_t');
expect(playlist.items.length).toBeLessThanOrEqual(100);