Imported from slhad/ytmanager (
AGENTS.md). Install upstream withnpx skills add slhad/ytmanager. Copyright stays with the author.
AGENTS.md - YouTube Manager (ytmanager)
Project Overview
ytmanager is a TypeScript-based command-line tool for managing YouTube live streams and videos via the YouTube Data API v3. It provides functionality to configure stream metadata, manage playlists, upload YouTube Shorts ("verticals"), set thumbnails, and update video descriptions with timestamps.
Technology Stack
| Component | Technology |
|---|---|
| Language | TypeScript (ES2022) |
| Runtime | Node.js 18+ |
| Package Manager | npm |
| Build Tool | TypeScript Compiler (tsc) |
| Testing | Jest with ts-jest |
| Linting | ESLint with @typescript-eslint |
| CLI Framework | @rushstack/ts-command-line |
| API Client | Google APIs (googleapis) |
| Date/Time | Luxon |
| HTTP Server | Express (for OAuth flow) |
| Bundling | pkg (for Windows executable) |
Repository Structure
ytmanager/
├── src/ # TypeScript source files
│ ├── index.ts # Main entry point, YouTube API logic
│ ├── cmd.ts # CLI command definitions using @rushstack/ts-command-line
│ └── persistence.ts # Stream/vertical history and library management
├── lib/ # Compiled JavaScript output (generated by tsc)
├── tests/ # Jest unit tests
│ └── persistence.test.ts # Tests for date/time extraction functions
├── dist/ # Bundled executable (Windows .exe)
├── scripts/ # Helper scripts (currently empty)
├── .vscode/ # VSCode configuration (launch, settings, tasks)
├── config.json # OAuth tokens and configuration (gitignored)
├── creds.json # Google API credentials (gitignored)
├── streamLib.json # Stream library history (gitignored)
├── videos.json # Video data cache (gitignored)
├── package.json # npm configuration and dependencies
├── tsconfig.json # TypeScript compiler configuration
├── jest.config.js # Jest test configuration
├── .eslintrc # ESLint configuration
└── README.md # Project documentation
Key Source Files
src/index.ts (Main Entry Point)
- Purpose: Main application logic and YouTube API interactions
- Key Functions:
getLiveBroadcast()- Fetch current live stream infogetVideo()- Fetch video metadata by IDupdateVideo()- Update video metadata (title, description, tags, category, language)setTitleStream()- Update live broadcast titlesetCurrentStream()- Apply multiple settings to current streamsetCurrentThumbnail()- Upload video thumbnail with optional auto-compressionuploadVerticalsToYoutube()- Upload shorts/verticals to YouTubegetPlaylists()/getPlaylistsId()- Manage playlistsaddVideoInPlaylist()- Add video to playlistaskForAuth()- OAuth2 authentication flow using Express server
- OAuth Flow: Uses Google OAuth2Client with Express callback handler
src/cmd.ts (CLI Commands)
- Purpose: Define all CLI commands and parameters using
@rushstack/ts-command-line - Exports:
commandLineParserobject containing:cmd- Main command line parserflags- Global flags (verbose, pretty, history)actions- All available command actions
src/persistence.ts (Data Persistence)
- Purpose: Manage stream history and vertical metadata
- Key Types:
Vertical- YouTube Shorts metadataStream- Stream metadata with associated verticalsStreamLib- Root library structure
- Key Class:
StreamLibrary- Load/save stream library, manage verticals - Key Functions:
conversionVideoToStreamInfo()- Convert YouTube API response to Stream typeextractAndCompareDateTime()- Parse filename timestamps for vertical synchronizationconvertStreamToVerticalInfo()- Create vertical metadata from stream
Available CLI Commands
| Command | Description |
|---|---|
info |
Get current live stream and video info |
set-title |
Set stream title |
set-live-stream |
Set live stream title and description |
set-current-stream |
Comprehensive stream settings (title, description, tags, playlist, category, language) |
set-current-thumbnail |
Upload thumbnail image (supports auto-recompression) |
set-timestamps |
Add timestamps to video description |
get-playlists |
Get playlists by name |
get-playlist |
Get single playlist ID by name |
vertical-saved |
Link saved vertical to current stream |
vertical-info |
Update vertical metadata |
verticals-upload |
Upload unuploaded verticals to YouTube |
stream-settings |
Configure vertical upload settings |
update-dock-redirect |
Generate HTML redirect page for OBS dock chat |
serve |
Start REST API server to expose all CLI features via HTTP |
Global Flags
| Flag | Short | Description |
|---|---|---|
--verbose |
-v |
Enable verbose logging |
--pretty |
-p |
Pretty print JSON output |
--history |
-H |
Enable stream/vertical history tracking |
REST API Server
The serve command starts a local REST API server that exposes all CLI functionality via HTTP endpoints.
Starting the Server
# Start with default settings (localhost:3001)
ytmanager serve
# Custom port and host
ytmanager serve --port 8080 --host 0.0.0.0
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /api/endpoints |
List all available endpoints |
| GET | /api/stream/info |
Get current stream info |
| PUT | /api/stream/title |
Set stream title |
| PUT | /api/stream/live |
Set live stream info |
| PUT | /api/stream/current |
Set current stream settings |
| PUT | /api/stream/thumbnail |
Set thumbnail |
| PUT | /api/stream/timestamps |
Set timestamps |
| GET | /api/playlists |
Get playlists by name |
| GET | /api/playlist |
Get playlist ID by name |
| GET | /api/verticals/saved |
Get saved vertical info |
| PUT | /api/verticals/info |
Update vertical info |
| POST | /api/verticals/upload |
Upload verticals to YouTube |
| GET | /api/settings |
Get stream settings |
| PUT | /api/settings |
Update stream settings |
| PUT | /api/dock-redirect |
Update dock redirect page |
Example API Calls
# Get stream info
curl http://localhost:3001/api/stream/info
# Set stream title
curl -X PUT http://localhost:3001/api/stream/title \
-H "Content-Type: application/json" \
-d '{"title": "My Stream Title"}'
# Set current stream with multiple options
curl -X PUT http://localhost:3001/api/stream/current \
-H "Content-Type: application/json" \
-d '{
"title": "Stream Title",
"playlist": ["Gaming", "Live"],
"tags": ["gaming", "live"],
"category": "Gaming"
}'
# Get playlists
curl "http://localhost:3001/api/playlists?name=Gaming"
# Update settings
curl -X PUT http://localhost:3001/api/settings \
-H "Content-Type: application/json" \
-d '{"verticalVisibility": "public"}'
Development Commands
# Install dependencies
npm ci
# Build TypeScript to JavaScript
npm run build
# Run tests
npm test
# Run the CLI
npm start
# or directly: node lib/src/index.js <command>
# Generate CLI documentation
npm run doc
# Bundle into Windows executable
npm run bundle
Configuration Files
creds.json (Required)
Google API credentials with OAuth2 client configuration:
{
"installed": {
"client_id": "<your-client-id>",
"client_secret": "<your-client-secret>",
"redirect_uris": ["http://localhost:3000/callback"]
}
}
config.json (Auto-generated)
Stores OAuth tokens after authentication:
{
"code": "<auth-code>",
"tokens": {
"access_token": "...",
"refresh_token": "...",
"scope": "https://www.googleapis.com/auth/youtube.force-ssl",
"token_type": "Bearer",
"expiry_date": 1234567890
}
}
streamLib.json (Auto-generated)
Stream history and vertical library with settings:
{
"verticalsOptions": {
"path": "/path/to/verticals",
"addLinkToVideo": true,
"offsetLinkToVideoInSeconds": 0,
"visibility": "public"
},
"pageDock": "",
"thumbPath": "",
"watchUrl": "https://www.youtube.com/watch?v=",
"timestampsPath": "",
"streams": {}
}
Code Conventions
- No semicolons - ESLint enforces no semicolons at end of statements
- Double quotes - ESLint enforces double quotes for strings
- Strict TypeScript -
strict: truein tsconfig.json - ES2022 target - Uses modern JavaScript features
- CommonJS modules - Output format is CommonJS
Testing
Tests use Jest with ts-jest for TypeScript support. Test files are located in tests/:
persistence.test.ts- Tests datetime extraction and comparison for vertical file naming
Run tests with:
npm test
OAuth2 Authentication Flow
- First run triggers OAuth flow via Express server
- User visits authorization URL in browser
- Google redirects to callback URL with auth code
- App exchanges code for tokens and saves to
config.json - Subsequent runs use stored refresh token
Important Notes for AI Agents
-
Sensitive Files:
creds.json,config.json,streamLib.json, andvideos.jsoncontain sensitive data and are gitignored. Never commit these files. -
API Scope: Uses
youtube.force-sslscope for full YouTube Data API access. -
Thumbnail Limits: YouTube thumbnail size limit is 2MB. The tool supports auto-recompression using
imagemin-pngquant. -
Vertical/Shorts: "Verticals" refer to YouTube Shorts. The tool tracks them in
streamLib.jsonand can batch upload them. -
Environment Variables: Many CLI parameters support environment variable overrides (see parameter definitions in
cmd.ts). -
Build Output: Compiled JavaScript goes to
lib/directory, matching the binary entry point inpackage.json. -
Executable: The
bundlescript creates a standalone Windows executable usingpkg.