New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

discord-player-youtubei

Package Overview
Dependencies
Maintainers
0
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-player-youtubei - npm Package Compare versions

Comparing version 1.2.5-beta.4 to 1.2.5-beta.6

15

dist/index.d.ts

@@ -9,12 +9,2 @@ import { Track, BaseExtractor, ExtractorStreamable, SearchQueryType, ExtractorSearchContext, ExtractorInfo, Playlist, GuildQueueHistory } from 'discord-player';

interface RotatorShardOptions {
authentications: string[];
rotationStrategy: "shard";
currentShard: number;
}
interface RotatorRandomOptions {
authentications: string[];
rotationStrategy: "random";
}
type RotatorConfig = RotatorShardOptions | RotatorRandomOptions;
interface StreamOptions {

@@ -29,3 +19,2 @@ useClient?: InnerTubeClient;

streamOptions?: StreamOptions;
rotator?: RotatorConfig;
overrideBridgeMode?: "ytmusic" | "yt";

@@ -46,6 +35,6 @@ disablePlayer?: boolean;

static ytContext: AsyncLocalStorage<AsyncTrackingContext>;
rotatorOnEachReq: boolean;
static setClientMode(client: InnerTubeClient): void;
static getStreamingContext(): AsyncTrackingContext;
activate(): Promise<void>;
signIn(tokens: string): Promise<void>;
deactivate(): Promise<void>;

@@ -72,2 +61,2 @@ validate(query: string, type?: SearchQueryType | null | undefined): Promise<boolean>;

export { type AsyncTrackingContext, type RotatorConfig, type RotatorRandomOptions, type RotatorShardOptions, type StreamOptions, YoutubeiExtractor, type YoutubeiOptions, generateOauthTokens, getYoutubeiInstance, objectToToken, tokenToObject };
export { type AsyncTrackingContext, type StreamOptions, YoutubeiExtractor, type YoutubeiOptions, generateOauthTokens, getYoutubeiInstance, objectToToken, tokenToObject };

@@ -98,10 +98,2 @@ "use strict";

var import_node_async_hooks = require("async_hooks");
// lib/common/randomAuthToken.ts
function getRandomOauthToken(tokens) {
const randomInt = Math.round(Math.random() * (tokens.length - 1));
return tokens[randomInt];
}
// lib/Extractor/Youtube.ts
var YoutubeiExtractor = class _YoutubeiExtractor extends import_discord_player.BaseExtractor {

@@ -114,4 +106,2 @@ static identifier = "com.retrouser955.discord-player.discord-player-youtubei";

static ytContext = new import_node_async_hooks.AsyncLocalStorage();
rotatorOnEachReq = false;
#oauthTokens = [];
static setClientMode(client) {

@@ -137,5 +127,4 @@ if (!this.instance) throw new Error("Cannot find Youtubei's instance");

return _YoutubeiExtractor.ytContext.run({
useClient: this.options.streamOptions?.useClient ?? "WEB"
useClient: this.options.streamOptions?.useClient ?? "ANDROID"
}, async () => {
if (this.rotatorOnEachReq) await this.#rotateTokens();
return streamFromYT(q, this.innerTube, {

@@ -148,18 +137,5 @@ overrideDownloadOptions: this.options.overrideDownloadOptions

_YoutubeiExtractor.instance = this;
if (this.options.rotator) {
if (this.options.rotator.rotationStrategy === "shard") {
const tokenToUse = this.options.rotator.currentShard % this.options.rotator.authentications.length;
this.context.player.debug(`Shard count is ${this.options.rotator.currentShard} thus using rotator.authentication[${tokenToUse}]`);
await this.#signIn(this.options.rotator.authentications[tokenToUse]);
const info = await this.innerTube.account.getInfo();
this.context.player.debug(info.contents?.contents ? `Signed into YouTube using the name: ${info.contents.contents[0]?.account_name?.text ?? "UNKNOWN ACCOUNT"}` : `Signed into YouTube using the client name: ${this.innerTube.session.client_name}@${this.innerTube.session.client_version}`);
return;
}
this.#oauthTokens = this.options.rotator.authentications.map((v) => tokenToObject(v));
this.rotatorOnEachReq = true;
return;
}
if (this.options.authentication) {
try {
await this.#signIn(this.options.authentication);
await this.signIn(this.options.authentication);
const info = await this.innerTube.account.getInfo();

@@ -175,3 +151,3 @@ this.context.player.debug(info.contents?.contents ? `Signed into YouTube using the name: ${info.contents.contents[0]?.account_name?.text ?? "UNKNOWN ACCOUNT"}` : `Signed into YouTube using the client name: ${this.innerTube.session.client_name}@${this.innerTube.session.client_version}`);

}
async #signIn(tokens) {
async signIn(tokens) {
const tkn = tokenToObject(tokens);

@@ -264,7 +240,2 @@ await this.innerTube.session.signIn(tkn);

}
async #rotateTokens() {
this.context.player.debug("Rotation strategy 'random' detected. Attempting to rotate");
const token = getRandomOauthToken(this.#oauthTokens);
await this.innerTube.session.signIn(token);
}
async handle(query, context) {

@@ -274,3 +245,2 @@ if (context.protocol === "ytsearch") context.type = import_discord_player.QueryType.YOUTUBE_SEARCH;

if (!query.includes("list=RD") && import_extractor.YouTubeExtractor.validateURL(query)) context.type = import_discord_player.QueryType.YOUTUBE_VIDEO;
if (this.rotatorOnEachReq) await this.#rotateTokens();
if (context.type === import_discord_player.QueryType.YOUTUBE_PLAYLIST) {

@@ -443,3 +413,2 @@ const url = new URL(query);

if (!id) id = track.url.split("/").at(-1)?.split("?").at(0);
if (this.rotatorOnEachReq) await this.#rotateTokens();
const videoInfo = await this.innerTube.getInfo(id);

@@ -446,0 +415,0 @@ const next = videoInfo.watch_next_feed;

3

package.json
{
"name": "discord-player-youtubei",
"version": "1.2.5-beta.4",
"version": "1.2.5-beta.6",
"description": "An unofficial package to test the use of youtubei in discord-player v6.",

@@ -18,3 +18,2 @@ "main": "dist/index.js",

"dependencies": {
"undici": "^6.19.2",
"youtubei.js": "^10.3.0"

@@ -21,0 +20,0 @@ },

@@ -71,29 +71,4 @@ # Discord Player YouTubei

## Rotating your token
Since Youtube has a hard limt (which is not that strict), we can provide a rotator config when registering the extractor. View [Rotator](./Rotator.md)
## Types
#### RotatorShardOptions
| name | type | required |
| ---- | ---- | -------- |
| authentications | Array of string | true |
| rotationStrategy | "shard" | true |
| currentShard | number | true |
#### RotatorRandomOptions
| name | type | required |
| ---- | ---- | -------- |
| authentications | Array of string | true |
| rotationStrategy | "random" | true |
#### RotatorConfig
```ts
type RotatorConfig = RotatorShardOptions | RotatorRandomOptions
```
#### StreamOptions

@@ -113,3 +88,2 @@

| signOutOnDeactive | boolean | Revoke the tokens after deactivation |
| rotator | [RotatorConfig](#rotatorconfig) | The config of the rotator |
| overrideBridgeMode | "ytmusic" or "yt" | Override the bridging behavior |

@@ -122,15 +96,2 @@ | streamOptions | [StreamOptions](#streamoptions) | Configure streaming behavior |

```ts
interface RotatorShardOptions {
authentications: string[];
rotationStrategy: "shard";
currentShard: number;
}
interface RotatorRandomOptions {
authentications: string[];
rotationStrategy: "random";
}
type RotatorConfig = RotatorShardOptions | RotatorRandomOptions
interface YoutubeiOptions {

@@ -144,3 +105,2 @@ authentication?: string;

};
rotator?: RotatorConfig;
overrideBridgeMode?: "ytmusic" | "yt"

@@ -147,0 +107,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc