Implement pyotp functionality for YouTube video downloading with 2FA support#346
Implement pyotp functionality for YouTube video downloading with 2FA support#346
Conversation
Co-authored-by: sgbaird <45469701+sgbaird@users.noreply.github.com>
Co-authored-by: sgbaird <45469701+sgbaird@users.noreply.github.com>
|
@copilot so, how do I connect this with the Google account I want to use to download the videos? Reply in your comment |
To connect this with your Google account for YouTube video downloading, you need to set up 2FA on your Google account and configure the TOTP secret. Here's the step-by-step process: 1. Enable 2FA on Your Google Account
2. Get Your TOTP SecretWhen setting up the authenticator app, you'll see a QR code and a manual entry option. Choose manual entry to get the Base32 secret string (looks like "JBSWY3DPEHPK3PXP"). 3. Set Environment Variableexport YOUTUBE_TOTP_SECRET="your_base32_secret_here"4. Use in Your Codefrom ac_training_lab.video_editing import get_current_totp_for_youtube
# This will generate the current 6-digit code for your Google account
totp_code = get_current_totp_for_youtube()
print(f"Use this code for 2FA: {totp_code}")The TOTP functionality generates the same 6-digit codes that your authenticator app would show. When playwright automation encounters a 2FA prompt during YouTube authentication, you can use Note: This works with any TOTP-compatible service, not just YouTube specifically - it's the standard Google 2FA implementation. |
This PR implements TOTP (Time-based One-Time Password) functionality for use with playwright automation in YouTube video downloading workflows that require 2FA authentication.
Changes Made
Core TOTP Functionality
pyotpdependency tosetup.cfgsrc/ac_training_lab/video_editing/totp_utils.pywith lean, minimal TOTP utilities:generate_totp_code()- Generate TOTP codes from Base32 secretsverify_totp_code()- Verify TOTP codes against secretsget_totp_code_from_env()- Retrieve TOTP codes from environment variablescreate_totp_provisioning_uri()- Create URIs for authenticator app setupYouTube Integration
src/ac_training_lab/video_editing/yt_utils.pywith TOTP support:get_current_totp_for_youtube()- Get YouTube-specific TOTP from environmentdownload_youtube_with_totp()- Enhanced download function with 2FA supportTesting & Documentation
tests/test_totp_utils.pyandtests/test_youtube_totp.pydocs/totp_usage.mdexamples/totp_example.pydemonstrating real-world usagevideo-editingextras group for optional dependenciesUsage Example
Installation
The implementation is lean and minimal as requested, without fake/mock implementations in the core functionality. It's designed specifically for playwright automation workflows requiring YouTube 2FA authentication.
Fixes #345.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.