From 266e0d79d424ed0f5cfab269a7c97e8df7dafbac Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Tue, 6 Jan 2026 00:11:45 +0800 Subject: [PATCH] fix(blocks): add YouTube Shorts URL support (#11659) ## Summary Added support for parsing YouTube Shorts URLs (`youtube.com/shorts/...`) in the TranscribeYoutubeVideoBlock to extract video IDs correctly. ## Changes - Modified `_extract_video_id` method in `youtube.py` to handle Shorts URL format - Added test cases for YouTube Shorts URL extraction ## Related Issue Fixes #11500 ## Test Plan - [x] Added unit tests for YouTube Shorts URL extraction - [x] Verified existing YouTube URL formats still work - [x] CI should pass all existing tests --------- Co-authored-by: Ubbe --- autogpt_platform/backend/backend/blocks/youtube.py | 2 ++ autogpt_platform/backend/test/blocks/test_youtube.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/autogpt_platform/backend/backend/blocks/youtube.py b/autogpt_platform/backend/backend/blocks/youtube.py index 322cac35a8..e79be3e99b 100644 --- a/autogpt_platform/backend/backend/blocks/youtube.py +++ b/autogpt_platform/backend/backend/blocks/youtube.py @@ -111,6 +111,8 @@ class TranscribeYoutubeVideoBlock(Block): return parsed_url.path.split("/")[2] if parsed_url.path[:3] == "/v/": return parsed_url.path.split("/")[2] + if parsed_url.path.startswith("/shorts/"): + return parsed_url.path.split("/")[2] raise ValueError(f"Invalid YouTube URL: {url}") def get_transcript( diff --git a/autogpt_platform/backend/test/blocks/test_youtube.py b/autogpt_platform/backend/test/blocks/test_youtube.py index 1af7c31b9b..4d3bd9d800 100644 --- a/autogpt_platform/backend/test/blocks/test_youtube.py +++ b/autogpt_platform/backend/test/blocks/test_youtube.py @@ -37,6 +37,18 @@ class TestTranscribeYoutubeVideoBlock: video_id = self.youtube_block.extract_video_id(url) assert video_id == "dQw4w9WgXcQ" + def test_extract_video_id_shorts_url(self): + """Test extracting video ID from YouTube Shorts URL.""" + url = "https://www.youtube.com/shorts/dtUqwMu3e-g" + video_id = self.youtube_block.extract_video_id(url) + assert video_id == "dtUqwMu3e-g" + + def test_extract_video_id_shorts_url_with_params(self): + """Test extracting video ID from YouTube Shorts URL with query parameters.""" + url = "https://www.youtube.com/shorts/dtUqwMu3e-g?feature=share" + video_id = self.youtube_block.extract_video_id(url) + assert video_id == "dtUqwMu3e-g" + @patch("backend.blocks.youtube.YouTubeTranscriptApi") def test_get_transcript_english_available(self, mock_api_class): """Test getting transcript when English is available."""