A comprehensive API toolkit for YouTube signature decryption and Spotify token management
- π YouTube Signature Decryption - Decrypt YouTube signatures and n-parameters
- π STS Extraction - Extract signature timestamps from YouTube player scripts
- π΅ Spotify Token Management - Get Spotify access tokens via API or browser automation
- π Spotify Key Rotation - Automatic Spotify credential rotation with multiple Lavalink server support
- π‘ Parallel Server Updates - Update all Lavalink instances simultaneously
- π OpenAPI Documentation - Interactive API documentation with Swagger UI
- π Authentication - Secure YouTube endpoints with token-based auth
- β‘ High Performance - Built with Bun runtime for maximum speed
- π§© Modular Architecture - Clean, maintainable codebase with separation of concerns
- Bun v1.2.x or higher
# Clone the repository
git clone https://github.com/idMJA/LavaTools.git
cd LavaTools
# Install dependencies
bun installInstall Playwright's bundled Chromium automatically:
bunx playwright install chromium- Download Chromium
- Download a compatible Chromium build from https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html (choose your OS/arch, e.g. Linux x64).
- Extract the archive and upload the
chrome/chromiumbinary (and its folder) to your Pterodactyl server, e.g./home/container/chrome-linux/chrome. - Set the path in
.env:CHROME_PATH=/home/container/chrome-linux/chrome - Restart your server/container.
If CHROME_PATH is not set, Playwright will use its default browser (if installed).
npm startUpdate the configuration in src/config.ts:
export const Configuration: KiyomiConfiguration = {
server: {
host: "0.0.0.0",
port: 3000,
},
// Optional: Set custom browser path for Spotify token fetching
// browserPath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
logging: {
level: "info", // "error" | "warn" | "info" | "debug"
toFile: false,
filePath: "./logs/app.log",
},
spotify: {
fetchMethod: "api", // "api" | "browser"
},
youtube: {
auth: "your_secret_token", // Set your auth token here
},
};
// Configure Spotify key rotation for Lavalink (see src/config/key.ts)Update the key rotation configuration in src/config/key.ts:
export const KeyRotationConfiguration: KeyRotationConfig = {
lavalinkServers: [
// Primary Lavalink server
{
name: "Primary Lavalink",
host: "localhost",
port: 8080,
secure: false, // false for HTTP, true for HTTPS
password: "your_lavalink_password",
},
// Add more Lavalink servers for load balancing or redundancy
// {
// name: "Secondary Lavalink",
// host: "lavalink-2.example.com",
// port: 8080,
// secure: true,
// password: "your_lavalink_password_2",
// },
// {
// name: "Backup Lavalink",
// host: "backup.example.com",
// port: 2333,
// secure: true,
// password: "your_lavalink_password_3",
// },
],
keys: [
// Add your Spotify keys here
// {
// clientId: "your_client_id_1",
// clientSecret: "your_client_secret_1",
// spDc: "your_sp_dc_1",
// },
// Add more keys for rotation
// {
// clientId: "your_client_id_2",
// clientSecret: "your_client_secret_2",
// spDc: "your_sp_dc_2",
// },
],
rotationInterval: 60, // Rotate every 60 minutes
maxErrors: 3, // Rotate after 3 errors
autoRotate: true, // Enable automatic rotation
};# Development mode (with hot reload)
bun dev
# Production mode
bun startThe server will start at http://localhost:3000
Once the server is running, access the interactive API documentation:
- Swagger UI: http://localhost:3000/openapi
- OpenAPI JSON: http://localhost:3000/openapi/json
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check endpoint |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/spotify/token |
Get Spotify access token | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/api/key-rotation/status |
Get key rotation status and all configured servers | β |
POST |
/api/key-rotation/rotate |
Manually rotate to next key (updates all servers) | β |
POST |
/api/key-rotation/set-active |
Set specific key as active (updates all servers) | β |
POST |
/api/key-rotation/report-error |
Report error for current key | β |
Query Parameters:
force(optional): Force refresh token (1,yes,trueto enable)
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/youtube/decrypt_signature |
Decrypt YouTube signatures | β |
POST |
/api/youtube/get_sts |
Extract signature timestamp | β |
POST |
/api/youtube/resolve_url |
Resolve YouTube stream URL by decrypting signature and/or n parameter | β |
Authentication:
YouTube endpoints require an Authorization header with your configured token (no "Bearer" prefix).
curl -X POST http://localhost:3000/api/youtube/decrypt_signature \
-H "Content-Type: application/json" \
-H "Authorization: your_secret_token" \
-d '{
"encrypted_signature": "encrypted_sig_here",
"n_param": "n_param_here",
"player_url": "https://www.youtube.com/s/player/player_id/player.js"
}'curl -X POST http://localhost:3000/api/youtube/get_sts \
-H "Content-Type: application/json" \
-H "Authorization: your_secret_token" \
-d '{
"player_url": "https://www.youtube.com/s/player/player_id/player.js"
}'This endpoint decrypts s/sig and n query parameters on a stream URL using the provided player script URL (or the provided encrypted signature) and returns a resolved URL ready to be used by your client.
Example:
curl -X POST http://localhost:3000/api/youtube/resolve_url \
-H "Content-Type: application/json" \
-H "Authorization: your_secret_token" \
-d '{
"stream_url": "https://rX---sn-abcxyz.googlevideo.com/videoplayback?expire=...&s=ENCRYPTED_S&n=ENCRYPTED_N",
"player_url": "https://www.youtube.com/s/player/player_id/player.js",
"encrypted_signature": "ENCRYPTED_S",
"signature_key": "sig", # optional, defaults to 'sig'
"n_param": "ENCRYPTED_N" # optional; if not provided, the endpoint will look for `n` in stream_url
}'LavaTools includes an advanced Spotify key rotation system that automatically updates multiple Lavalink servers with fresh credentials.
- β Multiple Lavalink Support - Update multiple Lavalink servers simultaneously
- β Automatic Rotation - Rotate keys at specified intervals
- β Error Handling - Automatically rotate keys when errors are detected
- β Parallel Updates - Update all servers concurrently for fast synchronization
- β Flexible Configuration - Support for HTTP/HTTPS and custom ports
- Configure your Lavalink servers in
src/config/key.ts:
lavalinkServers: [
{
name: "Primary",
host: "lavalink-1.example.com",
port: 8080,
secure: true,
password: "PASSWORD1",
},
{
name: "Secondary",
host: "lavalink-2.example.com",
port: 8080,
secure: true,
password: "PASSWORD2",
},
]- Add your Spotify credentials:
keys: [
{
clientId: "client_id_1",
clientSecret: "client_secret_1",
spDc: "sp_dc_1",
},
{
clientId: "client_id_2",
clientSecret: "client_secret_2",
spDc: "sp_dc_2",
},
]- The system will automatically:
- Rotate keys at specified intervals
- Switch keys when errors are detected
- Update all configured Lavalink servers with new credentials
# Check rotation status (shows all configured servers)
curl http://localhost:3000/api/key-rotation/status
# Manually rotate key (updates all servers)
curl -X POST http://localhost:3000/api/key-rotation/rotate \
-H "Authorization: your_secret_token"
# Set specific key as active (updates all servers)
curl -X POST http://localhost:3000/api/key-rotation/set-active \
-H "Authorization: your_secret_token" \
-H "Content-Type: application/json" \
-d '{"keyIndex": 0}'
# Report an error (may trigger auto-rotation if threshold exceeded)
curl -X POST http://localhost:3000/api/key-rotation/report-error \
-H "Authorization: your_secret_token"{
"totalKeys": 2,
"currentKeyIndex": 0,
"currentKey": {
"clientId": "client_i...",
"errors": 0,
"lastUsed": "2024-10-19T10:30:00Z"
},
"autoRotationEnabled": true,
"rotationInterval": 60,
"lavalinkServers": [
{
"name": "Primary",
"url": "https://lavalink-1.example.com:8080"
},
{
"name": "Secondary",
"url": "https://lavalink-2.example.com:8080"
}
]
}src/
βββ config.ts # Application configuration
βββ index.ts # Application entry point
βββ server.ts # Elysia server setup
βββ routes/ # API route handlers
βββ types/ # TypeScript type definitions
βββ utils/ # Utility functions
βββ spotify/ # Spotify-related utilities
β βββ browser.ts # Browser automation for tokens
β βββ direct.ts # API-based token fetching
β βββ index.ts # Spotify client factory
βββ youtube/ # YouTube-related utilities
βββ decrypt.ts # Signature decryption logic
βββ sts.ts # STS extraction logic
βββ solver.ts # Main solver functions
βββ auth.ts # Authentication middleware
βββ types.ts # YouTube-specific types
# Development with hot reload
bun run dev
# Format code
bun run format
# Type checking
bun run --check src/index.ts- Create new utility functions in
src/utils/ - Define types in
src/types/ - Add routes in
src/server.tswith OpenAPI documentation - Update configuration if needed
This project builds upon the excellent work of several open-source projects:
- yt-cipher - Original Deno implementation of YouTube signature decryption
- ejs - Core JavaScript implementation for YouTube signature solving
- accessify - Original browser-based Spotify token implementation
- spotify-secrets - Spotify API secrets for direct token access
- The yt-dlp team for their continuous work on YouTube extraction
- All contributors to the above projects for making this implementation possible
- The Bun and Elysia communities for amazing tooling
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
If you encounter any issues or have questions, please open an issue on GitHub.
Made with πͺ by γ’γΌγͺγ£