Features
Individual Videos
Standard videos, Shorts, and premieres
Playlists
Public playlists with automatic preview
Channels
Channel uploads, custom URLs, and handles
Video Search
Search YouTube directly from OTT
Supported URL Formats
The YouTube adapter recognizes these URL patterns:Individual Videos
Playlists
When a video URL includes a playlist ID (except private playlists like “LL” or “WL”), OTT will load the entire playlist with that video highlighted.
Channels
API Key Setup
Getting an API Key
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the YouTube Data API v3
- Go to Credentials and create an API Key
- (Optional but recommended) Restrict the key to YouTube Data API v3
Configuration
Add your API key to your configuration file:Quota Limits
YouTube API has daily quota limits:- Default quota: 10,000 units per day
- Video metadata request: ~3 units
- Playlist request: ~3 units
- Search request: ~100 units
Fallback Method
When the API quota is exceeded, OpenTogetherTube automatically attempts a fallback method:- Scrapes the YouTube video page directly
- Extracts duration from page metadata
- Only works for video duration (not title, description, or thumbnail)
- Less reliable than the API method
youtube.ts:649-663 and uses regex patterns to extract video length from the HTML response.
Metadata Extraction
The YouTube adapter fetches comprehensive video metadata:| Property | API Part | Description |
|---|---|---|
| Title | snippet | Video title |
| Description | snippet | Video description (can be truncated) |
| Thumbnail | snippet | Medium or default thumbnail |
| Duration | contentDetails | Video length in seconds |
| Channel | snippet | Channel name |
Description Truncation
You can configure description length limits to reduce storage:Playlist & Channel Handling
Playlist Preview
When adding a playlist:- First 50 videos are fetched (configurable)
- Preview shown to user
- User confirms before adding to queue
- Private videos are automatically skipped
Channel Uploads
Channel URLs are converted to the channel’s “uploads” playlist:- Channel ID is resolved (may require web scraping for handles/custom URLs)
- Uploads playlist ID is retrieved from channel metadata
- Playlist ID is cached in Redis for future requests
- Videos are fetched from the uploads playlist
Channel playlist IDs are cached to avoid repeated API calls. The cache key format is
ytchannel:{type}:{id}.Search Functionality
OpenTogetherTube can search YouTube directly:Limitations
Not Supported
Livestreams
Active livestreams and premieres are automatically filtered out
Private Videos
Private and unlisted videos in playlists are skipped
Age-Restricted
May not work without authentication
Region-Locked
Depends on server location
Livestream Detection
The adapter checks theliveBroadcastContent field:
none= regular video (supported)live= active livestream (blocked)upcoming= scheduled premiere (blocked)
youtube.ts:474-486:
Caching
YouTube metadata is cache-safe (isCacheSafe: true), meaning:
- Video metadata is stored in the database
- Cached data can be reused for future requests
- Reduces API quota consumption
- Cache is updated when video is re-added
Error Handling
Common errors and their meanings:| Error | Cause | Solution |
|---|---|---|
OutOfQuotaException | Daily API quota exceeded | Wait 24 hours or enable fallback |
VideoNotFoundException | Video doesn’t exist or is private | Check URL and video availability |
InvalidVideoIdException | Malformed video ID | Verify URL format |
UnsupportedVideoType | Livestream detected | Only VOD videos are supported |
Configuration Options
Full configuration example:Implementation Details
Technical Details
Technical Details
The YouTube adapter is implemented in
server/services/youtube.ts and includes:- API Client: Uses axios with base URL
https://www.googleapis.com/youtube/v3 - Redis Integration: Caches channel-to-playlist mappings
- Bulk Operations: Supports fetching up to 50 videos in a single API call
- Partial Metadata: Can fetch only specific fields to reduce quota usage
- Error Recovery: Automatic fallback when quota is exceeded
canHandleURL(): URL pattern matching (line 158-177)getVideoId(): Extract video ID from various URL formats (line 192-205)fetchVideoInfo(): Single video metadata (line 249-256)fetchManyVideoInfo(): Bulk video metadata (line 258-276)fetchPlaylistVideos(): Playlist contents (line 374-427)searchVideos(): YouTube search (line 683-715)