Initial commit: Add playlist downloader project with UI and core functionality

This commit is contained in:
2026-06-28 10:34:48 +02:00
commit 605dede363
49 changed files with 8300 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
# YouTube Bot Detection Improvements - Summary
## Changes Made
### 1. Enhanced HTTP Headers (src/core/downloader.py)
- Updated User-Agent to Chrome 120 (more recent)
- Added more realistic HTTP headers:
- `Accept`: Full HTML/XML/WebP support
- `Accept-Encoding`: gzip, deflate
- `DNT`: 1 (Do Not Track)
- `Connection`: keep-alive
- `Upgrade-Insecure-Requests`: 1
### 2. Cookie Support
- Added automatic detection of `cookies.txt` file
- If cookies exist, they're automatically used for all requests
- Cookies provide authenticated session, much more reliable than User-Agent spoofing
### 3. Improved Retry Logic
- **Search phase**: Exponential backoff with longer delays for bot detection
- 4s → 8s → 16s → 32s → 64s
- Distinguishes between bot detection and other errors
- **Download phase**: Separate retry logic with 3 attempts
- 4s → 8s → 16s delays
- Handles format unavailability gracefully
### 4. Better Error Handling
- Distinguishes between different error types:
- Bot detection errors: Longer delays, more retries
- Format unavailable: No retry (video doesn't have audio)
- Other errors: Standard retry logic
- Cleaner error messages
### 5. Cookie Export Tools
- **export_youtube_cookies.py**: Improved with better instructions
- **YOUTUBE_BOT_DETECTION.md**: New troubleshooting guide
## How to Use Cookies
### Quick Start
1. Make sure you're logged in to YouTube in your browser
2. Run: `python export_youtube_cookies.py`
3. Done! The app will use cookies automatically
### Alternative (yt-dlp method)
```bash
yt-dlp --cookies-from-browser firefox -o /dev/null https://www.youtube.com
```
## What Changed in Code
### src/core/downloader.py
**_get_ydl_options():**
- Added cookie file detection
- Enhanced HTTP headers
- Updated User-Agent to Chrome 120
**download_best_match():**
- Longer delays for bot detection (4s, 8s, 16s, 32s, 64s)
- Better error classification
**_download_url():**
- Added retry logic for downloads
- Handles bot detection during download phase
- Distinguishes format errors from other errors
## Testing
The improvements have been tested with:
- ✅ Enhanced HTTP headers
- ✅ Cookie support (if available)
- ✅ Exponential backoff for bot detection
- ✅ Better error messages
## Backward Compatibility
- ✅ Works without cookies (uses User-Agent spoofing)
- ✅ Automatically uses cookies if available
- ✅ No breaking changes to existing code
- ✅ All existing features still work
## Next Steps
If you still get bot detection errors:
1. Try exporting cookies: `python export_youtube_cookies.py`
2. Wait a few hours (YouTube may have temporarily blocked your IP)
3. Try a different browser for cookie export
4. Consider using a VPN (if allowed in your region)