11# Playwright YouTube Downloader
22
3- This module provides an alternative method for downloading YouTube videos using Playwright browser automation. This is particularly useful for downloading private or unlisted videos from owned channels that may not be accessible via traditional methods like yt-dlp.
3+ This module provides a lean method for downloading YouTube videos using Playwright browser automation and YouTube Studio interface . This is particularly useful for downloading private or unlisted videos from owned channels that may not be accessible via traditional methods like yt-dlp.
44
55## Features
66
77- ** Browser Automation** : Uses Playwright to automate a real browser session
88- ** Google Account Login** : Automatically logs into a Google account to access owned videos
9- - ** Native YouTube Interface** : Uses YouTube's built- in download functionality
10- - ** Quality Selection ** : Supports selecting video quality (720p, 1080p, etc.)
9+ - ** YouTube Studio Interface** : Uses the three-dot ellipses menu in YouTube Studio for downloads
10+ - ** Simple Configuration ** : Minimal environment variables needed
1111- ** Multiple Videos** : Can download multiple videos in sequence
1212- ** Integration** : Integrates with existing yt-dlp functionality
13- - ** Flexible Configuration** : Environment variable based configuration
1413
1514## Installation
1615
@@ -23,16 +22,14 @@ playwright install chromium
2322
2423## Configuration
2524
26- Set up your credentials and preferences using environment variables:
25+ Set up your credentials using environment variables:
2726
2827``` bash
2928# Required credentials
3029export GOOGLE_EMAIL=" your-email@gmail.com"
3130export GOOGLE_PASSWORD=" your-app-password"
3231
3332# Optional settings
34- export YT_DOWNLOAD_DIR=" ./downloads"
35- export YT_DEFAULT_QUALITY=" 720p"
3633export YT_HEADLESS=" true"
3734export YT_PAGE_TIMEOUT=" 30000"
3835export YT_DOWNLOAD_TIMEOUT=" 300"
@@ -52,13 +49,12 @@ export YT_CHANNEL_ID="UCHBzCfYpGwoqygH9YNh9A6g"
5249``` python
5350from ac_training_lab.video_editing.playwright_yt_downloader import download_youtube_video_with_playwright
5451
55- # Download a single video
52+ # Download a video from YouTube Studio
5653downloaded_file = download_youtube_video_with_playwright(
57- video_id = " dQw4w9WgXcQ " ,
54+ video_id = " cIQkfIUeuSM " , # Example video ID from ac-hardware-streams
5855 email = " your-email@gmail.com" ,
5956 password = " your-app-password" ,
60- download_dir = " ./downloads" ,
61- quality = " 720p" ,
57+ channel_id = " UCHBzCfYpGwoqygH9YNh9A6g" , # ac-hardware-streams channel
6258 headless = True
6359)
6460
@@ -75,7 +71,6 @@ from ac_training_lab.video_editing.playwright_yt_downloader import YouTubePlaywr
7571with YouTubePlaywrightDownloader(
7672 email = " your-email@gmail.com" ,
7773 password = " your-app-password" ,
78- download_dir = " ./downloads" ,
7974 headless = False # Show browser for debugging
8075) as downloader:
8176
@@ -84,12 +79,13 @@ with YouTubePlaywrightDownloader(
8479 downloader.navigate_to_youtube()
8580
8681 # Download multiple videos
87- video_ids = [" video1 " , " video2 " , " video3 " ]
88- results = downloader.download_videos_from_list(video_ids, quality = " 1080p " )
82+ video_ids = [" cIQkfIUeuSM " , " another_video_id " ]
83+ channel_id = " UCHBzCfYpGwoqygH9YNh9A6g " # ac-hardware-streams
8984
90- for video_id, file_path in results.items():
91- if file_path:
92- print (f " ✓ { video_id} : { file_path} " )
85+ for video_id in video_ids:
86+ result = downloader.download_video(video_id, channel_id)
87+ if result:
88+ print (f " ✓ { video_id} : { result} " )
9389 else :
9490 print (f " ✗ { video_id} : Failed " )
9591```
@@ -108,8 +104,7 @@ manager = YouTubeDownloadManager(use_playwright=True)
108104result = manager.download_latest_from_channel(
109105 channel_id = " UCHBzCfYpGwoqygH9YNh9A6g" ,
110106 device_name = " Opentrons OT-2" ,
111- method = " playwright" , # or "ytdlp"
112- quality = " 720p"
107+ method = " playwright" # or "ytdlp"
113108)
114109
115110if result[' success' ]:
@@ -123,9 +118,9 @@ else:
123118``` bash
124119# Download specific video with Playwright
125120python -m ac_training_lab.video_editing.integrated_downloader \
126- --video-id dQw4w9WgXcQ \
127- --method playwright \
128- --quality 720p
121+ --video-id cIQkfIUeuSM \
122+ --channel-id UCHBzCfYpGwoqygH9YNh9A6g \
123+ --method playwright
129124
130125# Download latest from channel with yt-dlp
131126python -m ac_training_lab.video_editing.integrated_downloader \
@@ -143,26 +138,25 @@ python -m ac_training_lab.video_editing.integrated_downloader \
143138
1441391 . ** Browser Launch** : Starts a Chromium browser instance with download settings
1451402 . ** Google Login** : Navigates to Google sign-in and enters credentials
146- 3 . ** YouTube Navigation** : Goes to YouTube and verifies login status
147- 4 . ** Video Access** : Navigates to specific video pages
148- 5 . ** Download Trigger** : Finds and clicks the download button in YouTube's interface
149- 6 . ** Quality Selection** : Chooses the preferred video quality
150- 7 . ** Download Monitoring** : Waits for download completion and returns file path
141+ 3 . ** YouTube Studio Navigation** : Goes to YouTube Studio for the specific video
142+ 4 . ** Three-Dot Menu** : Finds and clicks the three vertical ellipses (⋮) button
143+ 5 . ** Download Option** : Selects the "Download" option from the dropdown menu
144+ 6 . ** Download Monitoring** : Waits for download completion and returns file path
151145
152146## Browser Selectors
153147
154- The downloader uses multiple fallback selectors to find YouTube's download interface elements, as these can change over time:
148+ The downloader uses multiple fallback selectors to find YouTube Studio's interface elements, as these can change over time:
155149
156- - Download buttons : ` button[aria-label*="Download "] ` , ` button:has-text("Download ") ` , etc.
157- - Three-dot menus : ` button[aria-label*="More actions"] ` , ` yt-icon- button[aria-label*="More"] ` , etc.
158- - Quality options: Text-based and aria-label selectors
150+ - ** Three-dot ellipses menus ** : ` button[aria-label*="More "] ` , ` button:has-text("⋮ ") ` , etc.
151+ - ** Download options ** : ` text="Download" ` , ` button:has-text("Download") ` , etc.
152+ - ** Studio pages ** : ` [data-testid="video-editor"] ` for page load verification
159153
160154## Error Handling
161155
162156The system includes comprehensive error handling for:
163157
164158- ** Authentication failures** : Invalid credentials, 2FA requirements
165- - ** Network timeouts** : Configurable timeout values
159+ - ** Network timeouts** : Configurable timeout values
166160- ** Element not found** : Multiple selector fallbacks
167161- ** Download failures** : File system and browser download issues
168162
@@ -175,15 +169,15 @@ The system includes comprehensive error handling for:
175169 - Use App Password for 2FA accounts
176170 - Verify account access to target videos
177171
178- 2 . ** Download Button Not Found**
172+ 2 . ** Three-Dot Menu Not Found**
179173 - Video may not have download option
180- - Account may not have permission
181- - YouTube interface may have changed
174+ - Account may not have permission to video
175+ - YouTube Studio interface may have changed
182176
1831773 . ** Download Timeout**
184178 - Increase ` YT_DOWNLOAD_TIMEOUT `
185179 - Check network connection
186- - Try lower quality setting
180+ - Ensure sufficient disk space
187181
1881824 . ** Browser Issues**
189183 - Run ` playwright install chromium `
0 commit comments