YouTube Thumbnail Extractor
A Python module to extract thumbnail URLs from YouTube video URLs with support for multiple quality options and URL verification.
Features
- Extract thumbnails from various YouTube URL formats
- Support for multiple thumbnail qualities (maxresdefault, sddefault, hqdefault, mqdefault, default)
- Optional URL verification to check if thumbnails actually exist
- Handle single URLs or batch processing of multiple URLs
- Simple, clean API with comprehensive error handling
Installation
pip install extract-youtube
Quick Start
from extractor import YouTubeThumbnailExtractor
# Create an instance
extractor = YouTubeThumbnailExtractor()
# Extract thumbnail from a single URL
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
thumbnail = extractor.extract_thumbnail(url)
if thumbnail:
print(f"Video ID: {thumbnail.video_id}")
print(f"Best thumbnail: {thumbnail.url}")
print(f"High quality: {thumbnail.hqdefault}")
print(f"Medium quality: {thumbnail.mqdefault}")
Supported URL Formats
The extractor supports all common YouTube URL formats:
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://www.youtube.com/embed/VIDEO_IDhttps://www.youtube.com/v/VIDEO_ID- And more variations with or without
www.andhttps://
API Reference
YouTubeThumbnailExtractor
Methods
extract_thumbnail(url, quality='maxresdefault', verify_existence=False)
Extract thumbnail information from a single YouTube URL.
Parameters:
url(str): YouTube video URLquality(str): Preferred thumbnail quality (default: 'maxresdefault')verify_existence(bool): Whether to verify thumbnail exists via HTTP request
Returns: ThumbnailInfo object or None if invalid URL
extract_thumbnails(urls, quality='maxresdefault', verify_existence=False)
Extract thumbnails from multiple YouTube URLs.
Parameters:
urls(List[str]): List of YouTube video URLsquality(str): Preferred thumbnail qualityverify_existence(bool): Whether to verify thumbnails exist
Returns: List of ThumbnailInfo objects
ThumbnailInfo
Data class containing thumbnail information:
video_id: YouTube video IDurl: Best quality thumbnail URL based on preferencesmaxresdefault: 1280x720 thumbnail URLsddefault: 640x480 thumbnail URLhqdefault: 480x360 thumbnail URLmqdefault: 320x180 thumbnail URLdefault: 120x90 thumbnail URL
Thumbnail Quality Options
| Quality | Resolution | Description |
|---|---|---|
| maxresdefault | 1280x720 | Highest quality (may not exist for all videos) |
| sddefault | 640x480 | Standard definition |
| hqdefault | 480x360 | High quality |
| mqdefault | 320x180 | Medium quality |
| default | 120x90 | Lowest quality (always available) |
Usage Examples
Basic Usage
from extractor import YouTubeThumbnailExtractor
extractor = YouTubeThumbnailExtractor()
# Single URL
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
thumbnail = extractor.extract_thumbnail(url)
print(thumbnail.url)
Batch Processing
urls = [
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'https://youtu.be/jNQXAC9IVRw',
'https://www.youtube.com/embed/M7lc1UVf-VE'
]
thumbnails = extractor.extract_thumbnails(urls)
for thumb in thumbnails:
print(f"{thumb.video_id}: {thumb.url}")
With URL Verification
# Verify that thumbnail URLs actually exist
thumbnail = extractor.extract_thumbnail(
url,
quality='hqdefault',
verify_existence=True
)
Command Line Interface
The package also includes a command-line tool:
# Extract thumbnails from URLs in a file
extract-youtube --url-file urls.txt --quality hqdefault --verify
# Help
extract-youtube --help
Error Handling
The extractor gracefully handles various error conditions:
- Invalid YouTube URLs return
None - Network errors during verification are handled gracefully
- Missing thumbnails fall back to lower quality options
Requirements
- Python 3.8+
- requests >= 2.25.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
1.0.0 (2025-09-12)
- Initial release
- Support for all major YouTube URL formats
- Multiple thumbnail quality options
- Optional URL verification
- Batch processing capabilities
- Command-line interface
Metadata
Release files for extract-youtube 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| extract_youtube-1.0.0.tar.gz | 6.7 kB | Without provenance | Details for extract_youtube-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| extract_youtube-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for extract_youtube-1.0.0-py3-none-any.whl |
Total release size: 14.4 kB
Release files / extract_youtube-1.0.0.tar.gz
| Download URL | extract_youtube-1.0.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce0c16f8942cd3f29b9f47242f22393bce405cf5cee5692e822d4bc5968cfaaf
|
|
BLAKE2b-256 checksum How to use checksums |
abc93e9f86ed14f121fe7dfce7ac4f09a08839660130609f040ad61e606346ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / extract_youtube-1.0.0-py3-none-any.whl
| Download URL | extract_youtube-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1790565fe56dccb0f6ff004ead79d601844a5680bc1c3f988c83b3fe8ee32686
|
|
BLAKE2b-256 checksum How to use checksums |
93f4092d0fd3f05094181217354b9a88c942f61c702c77767b1d61d6b175f51c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for extract-youtube 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.