Automated YouTube Live Chat URL management and π cross-device stream link sharing for OBS Studio.
2025-09-28.13-18-19_x264.mp4
- Usage:
- My everyday Dual-Channel live-streaming setup:
- Other wonderful OBS stuff:
- Products that functions similarly to this one:
- Features
- How It Works
- Installation
- Configuration
- YouTube API Setup
- Multi-PC Setup
- API Quota Management
- Log Format
- Troubleshooting
- Contributing
- License
- Disclaimer
- π Automatic Chat URL Detection
- Primary HTML parsing method with API fallback for reliable video ID detection
- π Cross-Device Stream Sharing
- Share live stream links between multiple computers automatically (with verysync)
- β‘ Real-time Monitoring
- Continuous browser source URL monitoring and correction with periodic video ID updates
- π‘οΈ Enhanced API Protection
- Advanced quota management with exponential backoff, request rate limiting, and consecutive failure tracking
- π Auto Browser Refresh
- Automatic browser source cache refresh every 4 seconds to prevent chat display issues
- π JSON Logging
- Structured logging system for stream data synchronization with timestamped entries
- π― Smart Channel Input
- Supports channel IDs, handles (@username), and full YouTube URLs with intelligent normalization
- βοΈ Thread-Safe Operations
- Background processing with thread locks for reliable multi-timer coordination
- π§ Pending Video ID System
- Smooth video ID transitions with background updates to prevent chat interruption
- Stream Detection β Automatically detects stream start/stop events and initializes chat monitoring
- Video ID Fetching β Uses HTML parsing (primary) and YouTube API (fallback) to find live video IDs
- URL Management β Updates OBS browser source with correct YouTube Studio chat popout URLs
- Cross-Device Sync β Writes/reads JSON log files for automatic stream link sharing between computers
- Real-time Updates β Periodic video ID updates and browser source refresh to maintain chat connectivity
- Smart Retry Logic β Exponential backoff with failure tracking for robust error recovery
- Background Processing β Thread-safe background video ID updates with pending system for seamless transitions
- Download the script file
youtube_livechat_sync.py - In OBS Studio, go to Tools β Scripts
- Click the + button and select the downloaded script
- Configure the required settings (see Configuration section)
| Setting | Description | Example |
|---|---|---|
| YouTube API Key | YouTube Data API v3 key (Optional - HTML parsing works without it) | AIza... |
| Channel Handle/ID/URL | YouTube channel identifier (multiple formats supported) | @username or UC... or full URL |
| Browser Source Name | Name of your OBS browser source for chat display | YouTube Chat |
| Computer Identifier | Unique name for this computer in multi-PC setups | StreamPC1 |
| Write Log File Path | Directory or file path where this PC writes its stream logs | C:\StreamLogs\PC1.jsonl |
| Read Log Directory Path | Directory path to read other PC's stream logs | \\OtherPC\SharedLogs\PC2.jsonl |
| Setting | Default | Description |
|---|---|---|
| Base Init Interval (sec) | 1 | Initial retry interval for stream detection |
| Monitor & Refresh Interval (sec) | 4 | Frequency of URL monitoring and browser refresh |
| Maximum Init Attempts | 3 | Maximum initialization retry attempts |
| Max Init Retry Interval (sec) | 30 | Maximum retry interval with exponential backoff |
| Video ID Update Interval (sec) | 30 | Frequency of background video ID updates |
Note: API key is now optional - the script primarily uses HTML parsing which doesn't require API quota.
For API fallback functionality:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable YouTube Data API v3
- Create credentials (API Key)
- Copy the API key to the script configuration
For cross-device streaming setups:
- PC 1 (Main): Set
Write Log File Pathto a shared folder - PC 2 (Secondary): Set
Read Log Directory Pathto the same shared folder - Both PCs will automatically sync stream links through JSON log files
\SharedFolder\StreamLogs\
βββ MainPC.jsonl # Written by main streaming PC
βββ SecondaryPC.jsonl # Written by secondary PC
Enhanced quota protection system:
- Primary HTML Parsing: Reduces API dependency by 90%+ with intelligent page parsing
- Request Rate Limiting: Thread-safe request spacing with minimum 2-second intervals
- Exponential Backoff: Dynamic interval calculation (1.5x multiplier) up to 30s maximum
- Failure Tracking: Consecutive failure counting for intelligent retry logic
- Quota Monitoring: Real-time API usage tracking and logging with detailed statistics
Stream data is logged in JSON Lines format:
{
"timestamp": "2024-01-15T14:30:00.123456",
"videoId": "dQw4w9WgXcQ",
"shareLink": "https://youtube.com/live/dQw4w9WgXcQ?feature=share",
"popoutChatUrl": "https://studio.youtube.com/live_chat?is_popout=1&v=dQw4w9WgXcQ",
"sourceComputer": "StreamPC1"
}
- Monitor OBS Script Log: Check timestamped log entries for detailed operation status
- Verify Channel Input: Test different channel input formats (@handle, channel ID, full URL)
- Check File Permissions: Ensure read/write access to log directories
- Network Connectivity: Verify network access between PCs for cross-device sync
- Browser Source Settings: Confirm browser source URL updates are working correctly
- API Usage Tracking: Monitor quota usage in logs to optimize API calls
Contributions welcome! Please feel free to submit issues, feature requests, or pull requests. Focus areas:
- Currently, the initial acquisition of HTML methods is a bit slow, but the API methods are fast.
When just clicked on the live broadcast, the script and the push stream were started at the same time, which may be a bit stuck. (This problem should no longer exist now.)- Long-term polling HTML method update id may over-consuming upload bandwidth? (But it's not a matter for live broadcasters?)
- More stable timed polling: Does the logic of HTML request timeout need to set the maximum time limit?
- Real multithreaded multi-timer in non-python?
GPLv3.0 License - feel free to use and modify for your streaming needs.
- This tool uses HTML parsing as primary method and YouTube Data API v3 as fallback.
- Please be mindful of your API quota limits and YouTube's Terms of Service.
- The HTML parsing method may be affected by YouTube page structure changes.
β If this script helps your streaming setup, please give it a star!