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
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-player-youtubei

An unofficial package to test the use of youtubei in discord-player v6.

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by56.99%
Maintainers
0
Weekly downloads
 
Created
Source

Discord Player YouTubei

This is a preview the v7 version of the YouTube system that discord-player will be using made backwards compatiable with v6.

  • Warning: the documentation on GitHub is for the edge version of this package. Refer to this for more information

Installation

$ npm install discord-player-youtubei
# ----------- or -----------
$ yarn add discord-player-youtubei

Usage

Typescript and ESM
import { YoutubeiExtractor } from "discord-player-youtubei"

const player = useMainPlayer() // or new Player()

player.extractors.register(YoutubeiExtractor, {})
CommonJS
const { YoutubeiExtractor } = require("discord-player-youtubei")

const player = useMainPlayer() // or new Player()

player.extractors.register(YoutubeiExtractor, {})

I have seen many people registering the extractor in their commands. DO NOT DO THIS

How Discord Player Youtubei handles bridging

As of 1.2.1, discord-player-youtubei will detect if you are signed in or not and will use YouTube music streaming system. If this is not available, the extractor will use normal YouTube.

You can override this behavior using the overrideBridgeMode option. See the extractor options below for more information regarding the types

Signing into YouTube

[!WARNING] Recent developments have lead to the follow piece of code not working as intended. Please use cookies instead.

First run the following command

$ npx --no discord-player-youtubei

The token will be printed out shortly

In case of errors, you can directly run the generateOauthTokens function exported by discord-player-youtubei

import { YoutubeiExtractor } from "discord-player-youtubei"

const player = useMainPlayer()
/**
 * getOauthTokens is not a real function exported by discord-player-youtubei.
 * It is simply a placeholder for the actual oauth tokens
 * 
 * Do not just put in access token. Put in the entire string.
 */
const oauthTokens = getOauthTokens() // The tokens printed from step above

player.extractors.register(YoutubeiExtractor, {
    authentication: oauthTokens
})

Types

StreamOptions
nametypedescriptionrequired
useClientInnerTubeClientWhich client to get the stream fromfalse
highWaterMarknumberHow many bytes the stream can hold. The more bytes allocated, the smoother the stream at the cost of more memory usagefalse
YoutubeiOptions
nametypedescription
authenticationstringThe auth token
overrideDownloadOptionsDownloadOptionsOverride the default download options
createStreamfn (q, ext): Promise<string|Readable>Override the streaming function
signOutOnDeactivebooleanRevoke the tokens after deactivation
overrideBridgeMode"ytmusic" or "yt"Override the bridging behavior
streamOptionsStreamOptionsConfigure streaming behavior
disablePlayerbooleanDisable the JavaScript player. Use ANDORID client for streaming when using this
innertubeConfigRawInntertubeConfigRawOptions passed to .create()
trustedTokensTrustedTokenConfigThe trusted tokens passed to YouTube to avoid bans
cookiestringThe cookies passed to innertube similar to ytdl cookies
proxyProxyAgentDefine a proxy to route all the requests
peersPeerInfoStream from peers allowing to bypass some IP block

TrustedTokenConfig

Rename of GeneratorReturnData
All properties are required

nametypedescription
visitorDatastringThe visitor data of the PoToken
poTokenstringThe trusted token of the YouTube client

PeerInfo

nametypedescription
urlstringThe base URL of the peer
parseParserFunction?Parse the URL for the peer for streaming

ParserFunction

RAW: (url: string, id: string) => string

Parameters
nameindextypedescription
url0stringThe base URL of the peer
id1stringThe YouTube video ID
Return

The function must return a string that is a URL that returns an audio stream when requested

Raw Types

export interface StreamOptions {
  useClient?: InnerTubeClient;
  highWaterMark?: number;
}

export interface RefreshInnertubeOptions {
  filePath: string;
  interval?: number;
}

export interface PeerInfo {
  url: string;
  parse?: (url: string, id: string) => string;
}

export type TrustedTokenConfig = {
  poToken: string;
  visitorData: string;
};

export type QueryBridgeModes = Partial<
  Record<SearchQueryType, "yt" | "ytmusic">
> & { default?: "yt" | "ytmusic" };

export interface YoutubeiOptions {
  authentication?: string;
  overrideDownloadOptions?: DownloadOptions;
  createStream?: (
    q: Track,
    extractor: YoutubeiExtractor,
  ) => Promise<string | Readable>;
  signOutOnDeactive?: boolean;
  streamOptions?: StreamOptions;
  overrideBridgeMode?: "ytmusic" | "yt" | QueryBridgeModes;
  disablePlayer?: boolean;
  ignoreSignInErrors?: boolean;
  innertubeConfigRaw?: InnerTubeConfig;
  trustedTokens?: TrustedTokenConfig;
  cookie?: string;
  proxy?: ProxyAgent;
  peers?: PeerInfo[];
}

Functions

classfunctionparamsstaticdescription
YoutubeiExtractorsetClientModeInnerTubeClienttrueSet the innertube client on the fly

Something isn't working?

Try installing an alpha or a beta build using npm install discord-player-youtubei@alpha or npm install discord-player-youtubei@beta. If no beta has been released, you can test the edge version by installing directly from github using npm install github:retrouser955/discord-player-youtubei --save If this still does not work or you installed a version that is lower than the main version, feel free to open an issue on our GitHub page

If you know how to fix it, please clone this repository and send us a pull request. As this is an open source project, any contributions are welcome!

Want to support us?

Just star this repo!

Notice Regarding YouTube Streaming

Streaming from YouTube is against their Terms of Service (ToS). Refer to LEGAL.md to view the risks using YouTube.

FAQs

Package last updated on 20 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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