Add Image Download Support (New Download Type)
## Summary
This PR adds a new IMAGE download type to Seal, allowing users to download video thumbnails and playlist covers at various quality levels.
## Features Added
### 1. New Download Type: IMAGE
- Added IMAGE to DownloadType enum
- Integrated into download dialog workflow
- Accessible via download type selector
### 2. ImageSelectionPage UI
- Material 3 design with checkboxes for thumbnail/playlist cover selection
- Quality selector with radio buttons:
- Low (default.jpg)
- Medium (mqdefault.jpg)
- High (hqdefault.jpg)
- HD (sddefault.jpg)
- Original (maxresdefault.jpg - default)
- Confirmation dialog before download
- Toast notifications for user feedback
### 3. Smart Quality Selection
- Implemented `pickBestImageUrl()` with HTTP HEAD request probing
- Automatic quality fallback: ORIGINAL → HD → HIGH → MEDIUM → LOW
- Pre-validates URLs before enqueuing downloads
- Only downloads images that actually exist (no 404 errors)
### 4. Robust Download Implementation
- Retry logic: 2 attempts with 1-second delay
- Timeout configuration: 5s for HEAD probes, 30s for downloads
- Proper Content-Type validation (`image/*`)
- File extension extracted from Content-Type header
- Clean filename generation: `<videoId>_<quality>.<ext>`
### 5. File Management
- Saves to `/Pictures/Seal/` directory
- MediaScanner integration for gallery apps
- Proper stream management and resource cleanup
## Technical Details
### Modified Files
- `PreferenceUtil.kt` - Added IMAGE enum value
- `DownloadDialogViewModel.kt` - Added ImageQuality enum and state management
- `ImageSelectionPage.kt` - New UI component (327 lines)
- `DownloaderV2.kt` - Image download orchestration
- `DownloadUtil.kt` - pickBestImageUrl() and downloadImageFromUrl()
- `FileUtil.kt` - getPicturesSealFile() helper
- `Task.kt` - ImageDownload TypeInfo
- `DownloadDialogV2.kt` - Image type routing and error handling
- `strings.xml` - Image-related strings
### Bug Fixes
- Fixed ErrorPage crash when handling FetchImages errors
- Fixed duplicated filename suffixes (e.g., "maxresmaxresdefault.jpg")
- Fixed file extension mismatches
## Testing
Tested with real YouTube thumbnails:
- ✅ Old videos with limited quality availability (automatic fallback works)
- ✅ Modern videos with all quality levels (uses requested quality)
- ✅ HEAD request validation (200 status + image/* Content-Type)
- ✅ Gallery integration (MediaScanner refresh)
- ✅ Clean filenames with correct extensions
## Checklist
- [x] Code follows project style guidelines
- [x] Added/updated relevant documentation
- [x] Tested on Android 15 (API 35)
- [x] No breaking changes
- [x] All existing tests pass
- [x] Added appropriate error handling
合并状态:未合并 1 条评论