Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.
—
Searches for videos using DuckDuckGo's video search with filtering options for resolution, duration, and licensing, returning comprehensive video metadata and source information.
Searches for videos using specified keywords with filtering and configuration options.
def videos(
keywords: str,
region: str = "us-en",
safesearch: str = "moderate",
timelimit: str | None = None,
resolution: str | None = None,
duration: str | None = None,
license_videos: str | None = None,
max_results: int | None = None,
) -> list[dict[str, str]]:
"""
DuckDuckGo videos search. Query params: https://duckduckgo.com/params.
Parameters:
- keywords (str): Search keywords/query terms
- region (str): Region code (us-en, uk-en, ru-ru, etc.). Defaults to "us-en".
- safesearch (str): Safety filter level ("on", "moderate", "off"). Defaults to "moderate".
- timelimit (str, optional): Time filter ("d", "w", "m" for day, week, month). Defaults to None.
- resolution (str, optional): Video resolution filter ("high", "standart"). Defaults to None.
- duration (str, optional): Duration filter ("short", "medium", "long"). Defaults to None.
- license_videos (str, optional): License filter ("creativeCommon", "youtube"). Defaults to None.
- max_results (int, optional): Maximum number of results to return. If None, returns results from first response only. Defaults to None.
Returns:
List of dictionaries with video search results containing video metadata
Raises:
- DuckDuckGoSearchException: Base exception for search errors
- RatelimitException: API request rate limit exceeded
- TimeoutException: Request timeout occurred
"""Basic video search:
from duckduckgo_search import DDGS
with DDGS() as ddgs:
videos = ddgs.videos("python tutorial")
for video in videos:
print(f"Video content: {video.get('content', 'N/A')}")
# Print all available fields
for key, value in video.items():
print(f" {key}: {value}")
print("---")Video search with filters:
from duckduckgo_search import DDGS
with DDGS() as ddgs:
# Search for high-quality, recent videos
videos = ddgs.videos(
keywords="machine learning explained",
region="us-en",
safesearch="moderate",
timelimit="w", # Past week
resolution="high",
duration="medium", # Medium-length videos
max_results=10
)
for video in videos:
print(f"Video: {video.get('content', 'N/A')}")
print("Available data:")
for key, value in video.items():
print(f" {key}: {value}")
print("---")Video search with Creative Commons licensing:
from duckduckgo_search import DDGS
with DDGS() as ddgs:
# Search for Creative Commons licensed videos
videos = ddgs.videos(
keywords="nature documentary",
license_videos="creativeCommon",
resolution="high",
duration="long",
max_results=15
)
for video in videos:
print(f"Creative Commons Video: {video.get('content', 'N/A')}")
for key, value in video.items():
print(f" {key}: {value}")
print("---")Video search with error handling:
from duckduckgo_search import DDGS
from duckduckgo_search.exceptions import (
DuckDuckGoSearchException,
RatelimitException,
TimeoutException
)
try:
with DDGS() as ddgs:
videos = ddgs.videos(
keywords="cooking tutorial",
duration="short",
max_results=20
)
print(f"Retrieved {len(videos)} videos")
for i, video in enumerate(videos, 1):
print(f"\nVideo {i}:")
for key, value in video.items():
print(f" {key}: {value}")
except RatelimitException as e:
print(f"Rate limit exceeded: {e}")
except TimeoutException as e:
print(f"Request timed out: {e}")
except DuckDuckGoSearchException as e:
print(f"Video search error: {e}")Regional video search:
from duckduckgo_search import DDGS
with DDGS() as ddgs:
# Search for videos in different regions
regions = ["us-en", "uk-en", "au-en", "de-de"]
for region in regions:
print(f"\nSearching in region: {region}")
videos = ddgs.videos(
keywords="local news",
region=region,
timelimit="d", # Past day
max_results=3
)
for video in videos:
print(f" Video: {video.get('content', 'N/A')}")Filter and process video results:
from duckduckgo_search import DDGS
with DDGS() as ddgs:
videos = ddgs.videos("data science", max_results=50)
# Filter videos by content availability
valid_videos = [v for v in videos if 'content' in v and v['content']]
print(f"Found {len(valid_videos)} videos with content data")
# Group by unique content (remove duplicates)
unique_videos = {}
for video in valid_videos:
content_key = video.get('content', '')
if content_key and content_key not in unique_videos:
unique_videos[content_key] = video
print(f"Unique videos: {len(unique_videos)}")
# Display unique videos
for video in unique_videos.values():
print(f"Video: {video.get('content', 'N/A')}")
for key, value in video.items():
print(f" {key}: {value}")
print("---")"d": Past day"w": Past week"m": Past month"high": High definition videos"standart": Standard definition videos (note: spelling as per API)"short": Short videos (typically under 4 minutes)"medium": Medium-length videos (typically 4-20 minutes)"long": Long videos (typically over 20 minutes)"creativeCommon": Creative Commons licensed videos"youtube": YouTube-specific licensing"on": Strict filtering, blocks adult content"moderate": Moderate filtering (default)"off": No filteringCommon region codes for localized video search results:
"us-en": United States (English)"uk-en": United Kingdom (English)"au-en": Australia (English)"ca-en": Canada (English)"de-de": Germany (German)"fr-fr": France (French)"ru-ru": Russia (Russian)"jp-jp": Japan (Japanese)Video search results are returned as dictionaries containing video metadata. The exact structure may vary, but typically includes:
Since the video search returns platform-specific metadata, it's recommended to iterate through all available fields in each result to access the complete data set, as shown in the usage examples above.
Install with Tessl CLI
npx tessl i tessl/pypi-duckduckgo-search