codepractice-ai / scripts /README.md
Mahdi Naser Moghadasi
Add automated tutorial video creator script
52664bd
|
Raw History Blame Contribute Delete
4.03 kB

Tutorial Video Creator

This script automates browser interactions to create a tutorial video showing how to use the CodePractice AI website.

Features

  • βœ… Automated browser navigation
  • βœ… Realistic mouse cursor movements
  • βœ… Smooth scrolling animations
  • βœ… Code typing simulation
  • βœ… Button clicking
  • βœ… LLM interaction simulation
  • βœ… Automatic video recording

Setup

  1. Install dependencies:

    npm install
    
  2. Install Playwright browsers:

    npx playwright install chromium
    
  3. Start your website (if running locally):

    npm run dev
    

Usage

Basic Usage

npm run tutorial

Or directly:

node scripts/create-tutorial-video.js

Custom URL

To record from a different URL (e.g., production):

WEBSITE_URL=https://your-website.com npm run tutorial

Configuration

Edit scripts/create-tutorial-video.js to customize:

  • Delays: Adjust timing between actions
  • Sample Code: Change the code that gets typed
  • LLM Questions: Modify the questions asked
  • Video Output: Change output directory and filename

Output

Videos are saved to: tutorial-videos/tutorial-YYYY-MM-DD.webm

Converting to MP4

Playwright records in WebM format. To convert to MP4:

# Install ffmpeg (if not already installed)
# macOS: brew install ffmpeg
# Ubuntu: sudo apt-get install ffmpeg

# Convert video
ffmpeg -i tutorial-videos/tutorial-2025-12-20.webm \
       -c:v libx264 \
       -c:a aac \
       tutorial-videos/tutorial-2025-12-20.mp4

What the Script Does

  1. Opens the website in a browser
  2. Shows the Home Page with scrolling
  3. Selects a topic (Array) and difficulty (Easy)
  4. Clicks "Start Practicing" button
  5. Views the question on Practice Page
  6. Types code in the editor
  7. Clicks Run button to execute code
  8. Opens Interview Helper (LLM)
  9. Asks a question in the LLM
  10. Modifies code and asks another question

Customization

Change Sample Code

Edit the sampleCode in the CONFIG object:

sampleCode: `def your_function():
    # Your code here
    pass`,

Change LLM Questions

Edit the llmQuestions array:

llmQuestions: [
  "Your first question here",
  "Your second question here",
],

Adjust Timing

Modify the delays object:

delays: {
  short: 500,    // Quick pause
  medium: 1000,  // Normal pause
  long: 2000,    // Longer pause
  typing: 50,    // Delay between keystrokes
  scroll: 300,   // Scroll animation time
},

Troubleshooting

Browser doesn't open

  • Make sure Playwright browsers are installed: npx playwright install chromium
  • Check that headless is set to false in the script

Elements not found

  • The script uses flexible selectors, but you may need to adjust them based on your HTML structure
  • Check browser console for errors
  • Increase timeout values if needed

Video not recording

  • Make sure the output directory exists
  • Check file permissions
  • Wait a few seconds after script completes for video to be written

Cursor not visible

  • Make sure headless: false is set
  • The cursor should be visible in the recorded video

Tips

  1. Run locally first: Test with http://localhost:3000 before using production URL
  2. Adjust delays: Make them longer for slower demonstrations
  3. Customize code: Use code that matches your tutorial's focus
  4. Multiple takes: Run multiple times and pick the best recording
  5. Post-processing: Use video editing software to add:
    • Background music
    • Text annotations
    • Zoom effects
    • Transitions

Example Workflow

  1. Start your website: npm run dev
  2. Run the script: npm run tutorial
  3. Wait for completion (usually 1-2 minutes)
  4. Convert to MP4: ffmpeg -i tutorial-videos/tutorial-*.webm -c:v libx264 -c:a aac output.mp4
  5. Edit in video software (optional)
  6. Upload to YouTube/Vimeo or embed on your site