get_video_details
Retrieve comprehensive details about a YouTube video, including metadata and essential information, by providing the video ID. Ideal for extracting specific data for analysis or integration purposes.
Instructions
Get detailed information about a YouTube video
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| video_id | Yes |
Implementation Reference
- server.py:966-1011 (handler)Primary MCP tool handler for 'get_video_details'. This async function handles the tool invocation, parses the video_id argument, calls the underlying YouTubeService.get_video_details helper, formats the response with additional fields like URL and thumbnails, and handles errors.@mcp.tool( name="get_video_details", description="Get detailed information about a YouTube video", ) async def get_video_details(video_id: str) -> Dict[str, Any]: """ Get detailed information about a YouTube video Args: video_id (str): YouTube video ID Returns: Dict[str, Any]: Video details """ try: video_data = youtube_service.get_video_details(video_id) if not video_data.get('items'): return {'error': f"Video with ID {video_id} not found"} video = video_data['items'][0] # Format the response details = { 'id': video.get('id'), 'title': video.get('snippet', {}).get('title'), 'description': video.get('snippet', {}).get('description'), 'publishedAt': video.get('snippet', {}).get('publishedAt'), 'channelId': video.get('snippet', {}).get('channelId'), 'channelTitle': video.get('snippet', {}).get('channelTitle'), 'tags': video.get('snippet', {}).get('tags', []), 'viewCount': video.get('statistics', {}).get('viewCount'), 'likeCount': video.get('statistics', {}).get('likeCount'), 'commentCount': video.get('statistics', {}).get('commentCount'), 'duration': video.get('contentDetails', {}).get('duration'), 'dimension': video.get('contentDetails', {}).get('dimension'), 'definition': video.get('contentDetails', {}).get('definition'), 'thumbnails': video.get('snippet', {}).get('thumbnails'), 'url': f"https://www.youtube.com/watch?v={video_id}" } return details except Exception as e: logger.exception(f"Error in get_video_details: {e}") return {'error': str(e)}
- server.py:252-267 (helper)Core helper method in YouTubeService class that performs the actual YouTube Data API v3 call to fetch video details (snippet, contentDetails, statistics). Includes URL parsing and error handling. This is called by the tool handler and other functions.def get_video_details(self, video_id: str) -> Dict[str, Any]: """ Get detailed information about a specific YouTube video """ video_id = self.parse_url(video_id) try: response = self.youtube.videos().list( part='snippet,contentDetails,statistics', id=video_id ).execute() return response except HttpError as e: logger.error(f"Error getting video details: {e}") raise e
- server.py:966-969 (registration)MCP tool registration decorator that registers the get_video_details handler function with name 'get_video_details' and its description.@mcp.tool( name="get_video_details", description="Get detailed information about a YouTube video", )
- server.py:196-206 (helper)Supporting helper method used by get_video_details to parse YouTube URLs and extract video IDs.def parse_url(self, url: str) -> str: """ Parse the URL to get the video ID """ video_id_match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url) if not video_id_match: return url video_id = video_id_match.group(1) return video_id