# Session Summary: WB to Video Pipeline

**Date**: 2026-01-13
**Status**: ✅ Tested and working on native Linux
**Branch**: main
**Last update**: Pipeline tested successfully with Playwright

## What Was Built

### ✅ Complete Pipeline System
Full automation pipeline from Wildberries product URL to video generation prompts:

```
WB URL → Extract Data → Select Photo → Nanobanana (cleanup + 16:9) → Veo3 (video prompts)
```

### 📁 New Files Created

1. **[scripts/wb_to_video_prompts.py](scripts/wb_to_video_prompts.py)** - Main pipeline script
   - Extracts product ID from URL
   - Generates nanobanana prompts (cleanup + resize to 16:9)
   - Generates Veo3 video prompts (3 scene options)
   - Supports `--fetch` flag for automatic data fetching

2. **[scripts/wb_fetcher_selenium.py](scripts/wb_fetcher_selenium.py)** - Selenium-based fetcher ⭐ RECOMMENDED
   - Uses Selenium + ChromeDriver
   - Handles WB anti-bot protection
   - Extracts: name, images, price, description, type
   - **Ready for native Linux**

3. **[scripts/wb_fetcher.py](scripts/wb_fetcher.py)** - Playwright fetcher (alternative)

4. **[scripts/wb_fetcher_api.py](scripts/wb_fetcher_api.py)** - API fetcher (WB blocks this)

5. **[PIPELINE.md](PIPELINE.md)** - Complete workflow documentation

6. **[scripts/README.md](scripts/README.md)** - Detailed usage instructions

7. **[examples/202372804/](examples/202372804/)** - Working example with output

### 🎯 Generated Prompts Structure

The pipeline generates 3 types of outputs:

1. **Photo Selection** - Criteria for choosing best image from WB
2. **Nanobanana Prompts** - Clean text overlays + resize to 16:9
3. **Veo3 Video Prompts** - 3 scene options:
   - **A1**: Static beauty shot (low risk, safest)
   - **A2**: Camera rotation (medium risk, dynamic)
   - **B1**: Two-act narrative (high impact, studio → lifestyle)

## ✅ Previous Blocker (RESOLVED)

~~**Issue**: WSL environment lacks proper Chrome/Chromium libraries~~
- Fixed by moving to native Linux with Playwright
- Added stealth mode to bypass WB anti-bot protection

## 🚀 Setup on Native Linux (Completed)

### 1. Clone & Setup
```bash
git clone git@git.example.com:user/project.git
cd sm-video-gen
python3 -m venv venv
source venv/bin/activate
pip install -r scripts/requirements.txt
```

### 2. Install Chrome/Chromium
```bash
# Option A: Chromium (lighter)
sudo apt-get install -y chromium-browser

# Option B: Google Chrome (more stable)
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
```

### 3. Test Fetcher
```bash
cd scripts
python wb_fetcher_selenium.py "https://www.wildberries.ru/catalog/202372804/detail.aspx"
```

Expected output:
```json
{
  "url": "...",
  "product_id": "202372804",
  "name": "Сковорода гриль...",
  "type": "kitchenware",
  "images": ["https://basket-XX..."],
  ...
}
```

### 4. Run Full Pipeline
```bash
python wb_to_video_prompts.py --fetch "https://www.wildberries.ru/catalog/202372804/detail.aspx" > output.json
```

This will generate:
- Photo selection guidance
- Nanobanana prompts (cleanup + resize)
- Veo3 video prompts (3 scene options, fully customized for the product)

## 📝 Key Architecture Decisions

1. **Selenium over Playwright**: More compatible with system Chrome/Chromium
2. **Multiple fetchers**: Fallback options if one approach fails
3. **Headless by default**: Works on command-line-only Linux
4. **Product type detection**: Auto-detects kitchenware/fashion/electronics for better prompts
5. **16:9 format**: Standard for most video platforms

## 🔧 Configuration

### In wb_fetcher_selenium.py:
- `chrome_options.binary_location = '/usr/bin/chromium-browser'`
- Change if Chrome is in different location
- Or remove to let Selenium auto-detect

### In wb_to_video_prompts.py:
- Uses Selenium fetcher by default
- Swap import to use different fetcher if needed

## 📊 Example Product

**Test URL**: https://www.wildberries.ru/catalog/202372804/detail.aspx

See full output in: [examples/202372804/pipeline_output.json](examples/202372804/pipeline_output.json)

## ⚠️ Known Issues & Workarounds

1. **WB API blocked**: Direct API access returns 404
   - Solution: Use Selenium to scrape the page

2. **Image URLs guessing fails**: CDN structure changed
   - Solution: Extract real URLs from page DOM

3. **Anti-bot protection**: WB has Cloudflare-like protection
   - Solution: Wait 5+ seconds after page load

## 📚 Documentation Structure

```
sm-video-gen/
├── PIPELINE.md              ← Complete workflow overview
├── CLAUDE.md                ← Instructions for Claude Code
├── SESSION_SUMMARY.md       ← This file
├── prompts/                 ← Prompt library
│   ├── claude_vision/       ← Updated with two-act format
│   ├── banananano/          ← Cleanup prompts
│   └── video_generators/    ← Veo3 format guide
├── scripts/                 ← Automation tools
│   ├── README.md            ← Usage guide
│   ├── wb_to_video_prompts.py
│   ├── wb_fetcher_selenium.py  ← USE THIS
│   └── requirements.txt
└── examples/202372804/      ← Working example
```

## 🎬 Expected Workflow in Production

1. **Input**: WB product URL
2. **Fetch**: `python wb_to_video_prompts.py --fetch <URL>`
3. **Download**: Best photo from generated URLs
4. **Process**: Upload to nanobanana.ai with generated prompts
5. **Generate**: Upload processed 16:9 image to Veo3 with generated prompts
6. **Select**: Pick best video from 3-5 generations

## 💡 Future Improvements (TODO)

- [ ] Batch processing for multiple products
- [ ] Direct nanobanana API integration
- [ ] Direct Veo3 API integration (when available)
- [ ] Web UI (Streamlit/Gradio)
- [ ] Claude Vision API for automatic photo selection
- [ ] Video quality scoring

## 🐛 Debugging Tips

If Selenium fails on native Linux:

```bash
# Check Chrome version
google-chrome --version
# or
chromium-browser --version

# Test ChromeDriver download
python -c "from webdriver_manager.chrome import ChromeDriverManager; print(ChromeDriverManager().install())"

# Run with visible browser (debug)
# In wb_fetcher_selenium.py change: headless=False
```

## 📞 Contact

AI video generation project.

---

**Ready to continue on native Linux! 🚀**

All code committed and pushed to the git repository.
