# 🎬 VIDEO DQ - PowerShell Download Guide

## Quick Start

### Single Download

```powershell
.\Download-Video.ps1 -URL "https://www.instagram.com/reel/ABC123" -Platform "instagram"
```

### Batch Download from File

```powershell
.\Download-Batch.ps1 -ListFile "videos.txt"
```

---

## Installation

1. **Download both scripts:**
   - `Download-Video.ps1`
   - `Download-Batch.ps1`

2. **Save to a convenient location:**
   ```
   C:\Users\YourUsername\Videos\
   ```

3. **Allow scripts to run:**
   Open PowerShell as Administrator and run:
   ```powershell
   Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
   ```
   (Choose 'Y' when prompted)

4. **Navigate to script location:**
   ```powershell
   cd C:\Users\YourUsername\Videos
   ```

---

## Usage Examples

### Single Video Download

**Basic:**
```powershell
.\Download-Video.ps1 -URL "https://www.instagram.com/reel/ABC123" -Platform "instagram"
```

**With custom filename:**
```powershell
.\Download-Video.ps1 -URL "https://www.tiktok.com/video/123" -Platform "tiktok" -CustomFilename "my-favorite-dance"
```

**With custom NAS host:**
```powershell
.\Download-Video.ps1 -URL "https://..." -Platform "youtube" -NasHost "vdq.boxicube.com"
```

### Platform Names

Use these exact names for `-Platform`:
- `instagram` - Instagram Reels/Posts
- `facebook` - Facebook Videos
- `tiktok` - TikTok Videos
- `youtube` - YouTube Videos
- `twitter` - Twitter/X Videos
- `linkedin` - LinkedIn Videos
- `rumble` - Rumble Videos
- `other` - Any other platform

---

## Batch Download from File

### Create a Video List File

Create a file called `videos.txt` with one video per line:

**Format 1 - Basic (URL and Platform):**
```
https://www.instagram.com/reel/ABC123|instagram
https://www.tiktok.com/video/456|tiktok
https://www.youtube.com/watch?v=XYZ|youtube
```

**Format 2 - With Custom Filenames:**
```
https://www.instagram.com/reel/ABC123|instagram|my-first-video
https://www.tiktok.com/video/456|tiktok|awesome-dance
https://www.youtube.com/watch?v=XYZ|youtube|tutorial
```

**Format 3 - Mixed:**
```
# Instagram videos
https://www.instagram.com/reel/ABC123|instagram
https://www.instagram.com/reel/DEF456|instagram|cool-reel

# TikTok videos
https://www.tiktok.com/video/789|tiktok
https://www.tiktok.com/video/101112|tiktok|dance-video
```

### Run Batch Download

```powershell
.\Download-Batch.ps1 -ListFile "videos.txt"
```

**With options:**
```powershell
# Use different NAS host
.\Download-Batch.ps1 -ListFile "videos.txt" -NasHost "192.168.1.100"

# Add 5 second delay between downloads
.\Download-Batch.ps1 -ListFile "videos.txt" -Delay 5

# Skip duplicate detection
.\Download-Batch.ps1 -ListFile "videos.txt" -SkipDuplicates
```

---

## Output Examples

### Successful Single Download

```
============================================================
🎬 VIDEO DQ - Download Script
============================================================
ℹ Testing connection to NAS (192.168.69.105:3001)...
✓ Connected to NAS!
ℹ Preparing download request...
ℹ URL: https://www.instagram.com/reel/ABC123
ℹ Platform: instagram
ℹ Filename: auto

ℹ Sending request to NAS...
✓ Download successful!
✓ File: Cool Video Title.mp4
ℹ Size: 125.3 MB
ℹ Path: /volume2/video/videoDQ/downloads/instagram/Cool Video Title.mp4
✓ Done!
```

### Batch Download Report

```
[1 / 50] Downloading: https://www.instagram.com/reel/ABC...
  Platform: instagram | Filename: auto
✓ Downloaded: Video Title 1.mp4

[2 / 50] Downloading: https://www.tiktok.com/video/123...
  Platform: tiktok | Filename: my-dance
⚠ Already had this video

[3 / 50] Downloading: https://www.youtube.com/watch?v=...
  Platform: youtube | Filename: auto
✓ Downloaded: Tutorial Video.mp4

...

============================================================
📊 BATCH DOWNLOAD REPORT
============================================================
Total URLs:        50
✓ Successful:      48
✗ Failed:          1
⚠ Duplicates:      1
============================================================
```

---

## Troubleshooting

### "Cannot reach NAS"

**Solution 1 - Check IP/Host:**
```powershell
# Test if NAS is reachable
ping 192.168.69.105
```

**Solution 2 - Specify correct NAS:**
```powershell
.\Download-Video.ps1 -URL "..." -Platform "instagram" -NasHost "vdq.boxicube.com"
```

**Solution 3 - Check videoDQ is running on NAS:**
```
# SSH to NAS
ssh user@192.168.69.105
pm2 status videoDQ
pm2 logs videoDQ
```

### "Authentication failed" (Instagram/TikTok)

Your cookies are expired. Re-export them:
1. Open Firefox on Windows
2. Visit instagram.com (or tiktok.com)
3. Use "Get Cookies .txt" extension → Export
4. Upload to NAS: `/volume2/video/videoDQ/cookies/www.instagram.com_cookies.txt`
5. Restart: `pm2 restart videoDQ`

### "Timeout" Error

The video is too large or connection is slow. Try again or increase timeout:
```powershell
# Edit the script and change TimeoutSec from 600 to 1200
# (double the timeout to 20 minutes)
```

### PowerShell script won't run

**Error:** "Cannot be loaded because running scripts is disabled"

**Fix:**
```powershell
# Run as Administrator, then:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Press 'Y' to confirm
```

---

## Advanced Usage

### Custom Download Folder

Currently videos are saved to NAS platform folders. You can edit the script to use custom paths by modifying the `-SavePath` parameter in the body.

### Logging Downloads

Redirect output to a file:
```powershell
.\Download-Batch.ps1 -ListFile "videos.txt" | Tee-Object -FilePath "download_log.txt"
```

### Schedule Batch Downloads

Create Windows Task Scheduler task to run daily:
```powershell
# Run as Administrator
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File 'C:\path\to\Download-Batch.ps1' -ListFile 'C:\path\to\videos.txt'"
$trigger = New-ScheduledTaskTrigger -Daily -At 3:00 AM
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "VideoDQ Batch Download" -Description "Daily video download"
```

---

## Tips & Tricks

✅ **Use the batch script for large playlists** - It's much faster than running single downloads

✅ **Test a few URLs first** - Run 3-5 downloads before queuing 100+

✅ **Add delays between downloads** - Use `-Delay 3` to be nice to Instagram/TikTok

✅ **Use meaningful filenames** - Makes it easier to find videos later

✅ **Check NAS logs if errors occur** - `pm2 logs videoDQ --lines 50`

✅ **Keep your cookies fresh** - Re-export every 2-3 weeks for Instagram

---

## Help & Support

Get help on any script:
```powershell
Get-Help .\Download-Video.ps1 -Full
Get-Help .\Download-Batch.ps1 -Full
```

Check script parameters:
```powershell
Get-Help .\Download-Video.ps1 -Parameter *
```
