Skip to content

Implement pyotp functionality for YouTube video downloading with 2FA support #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 22, 2025

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

  • Added pyotp dependency to setup.cfg
  • Created src/ac_training_lab/video_editing/totp_utils.py with lean, minimal TOTP utilities:
    • generate_totp_code() - Generate TOTP codes from Base32 secrets
    • verify_totp_code() - Verify TOTP codes against secrets
    • get_totp_code_from_env() - Retrieve TOTP codes from environment variables
    • create_totp_provisioning_uri() - Create URIs for authenticator app setup

YouTube Integration

  • Enhanced src/ac_training_lab/video_editing/yt_utils.py with TOTP support:
    • get_current_totp_for_youtube() - Get YouTube-specific TOTP from environment
    • download_youtube_with_totp() - Enhanced download function with 2FA support
  • Integration maintains backward compatibility with existing functionality

Testing & Documentation

  • Comprehensive test suite in tests/test_totp_utils.py and tests/test_youtube_totp.py
  • Usage documentation in docs/totp_usage.md
  • Example script in examples/totp_example.py demonstrating real-world usage
  • Added video-editing extras group for optional dependencies

Usage Example

from ac_training_lab.video_editing import (
    generate_totp_code, 
    download_youtube_with_totp
)

# Set environment variable: YOUTUBE_TOTP_SECRET="your_base32_secret"

# Generate TOTP code for 2FA
code = generate_totp_code("JBSWY3DPEHPK3PXP")

# Download with 2FA support (ready for playwright automation)
download_youtube_with_totp("video_id", code)

Installation

pip install ac-training-lab[video-editing]

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.

Copilot AI and others added 2 commits June 22, 2025 01:51
Co-authored-by: sgbaird <45469701+sgbaird@users.noreply.github.com>
Co-authored-by: sgbaird <45469701+sgbaird@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Implement pyotp Implement pyotp functionality for YouTube video downloading with 2FA support Jun 22, 2025
@Copilot Copilot AI requested a review from sgbaird June 22, 2025 01:54
Copilot finished work on behalf of sgbaird June 22, 2025 01:54
@sgbaird
Copy link
Member

sgbaird commented Jun 22, 2025

@copilot so, how do I connect this with the Google account I want to use to download the videos?

Reply in your comment

Copy link
Contributor Author

Copilot AI commented Jun 22, 2025

@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

  • Go to myaccount.google.com/security
  • Enable 2-Step Verification if not already enabled
  • Add an authenticator app (like Google Authenticator, Authy, etc.)

2. Get Your TOTP Secret

When 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 Variable

export YOUTUBE_TOTP_SECRET="your_base32_secret_here"

4. Use in Your Code

from 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 totp_code to programmatically enter the verification code.

Note: This works with any TOTP-compatible service, not just YouTube specifically - it's the standard Google 2FA implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement pyotp
2 participants