File size: 6,710 Bytes
6bf65c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# π YouTube Metadata Extractor - Windows Deployment Script
# This script deploys the project on a Windows Server
Write-Host "π Starting deployment of YouTube Metadata Extractor on Windows..." -ForegroundColor Green
# Configuration
$ProjectDir = "$env:USERPROFILE\YouTube"
$RepoUrl = "https://huggingface.co/spaces/dzianisBY/YouTube_Creator_MetaData"
$PythonEnv = "$ProjectDir\.venv"
# Function to print colored output
function Write-Status {
param($Message)
Write-Host "β
$Message" -ForegroundColor Green
}
function Write-Warning {
param($Message)
Write-Host "β οΈ $Message" -ForegroundColor Yellow
}
function Write-Error {
param($Message)
Write-Host "β $Message" -ForegroundColor Red
}
# Check if running as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Error "This script must be run as Administrator"
Write-Host "Please right-click PowerShell and select 'Run as Administrator'" -ForegroundColor Yellow
exit 1
}
# Install Chocolatey if not present
if (!(Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Status "Installing Chocolatey package manager..."
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
refreshenv
}
# Install required software
Write-Status "Installing system dependencies..."
choco install python git -y
refreshenv
# Create project directory
Write-Status "Setting up project directory..."
if (!(Test-Path $ProjectDir)) {
New-Item -ItemType Directory -Path $ProjectDir -Force
}
Set-Location $ProjectDir
# Clone or update repository
if (Test-Path ".git") {
Write-Status "Updating existing repository..."
git pull origin main
} else {
Write-Status "Cloning repository..."
git clone $RepoUrl .
}
# Create virtual environment
Write-Status "Setting up Python virtual environment..."
python -m venv $PythonEnv
& "$PythonEnv\Scripts\Activate.ps1"
# Install Python dependencies
Write-Status "Installing Python dependencies..."
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r telegram_requirements.txt
# Create .env file template if it doesn't exist
if (!(Test-Path ".env")) {
Write-Warning "Creating .env template file..."
@"
# YouTube API Configuration
YOUTUBE_API_KEY=your_youtube_api_key_here
# Telegram Bot Configuration
TELEGRAM_TOKEN=your_telegram_bot_token_here
# MCP Server Configuration
MCP_BASE_URL=https://youtube-bot.tuttech.net/api/mcp
# Gemini AI Configuration
GEMINI_API_KEY=your_gemini_api_key_here
# Server Configuration
HOST=0.0.0.0
PORT=8080
"@ | Out-File -FilePath ".env" -Encoding UTF8
Write-Warning "Please edit .env file with your actual API keys!"
Write-Warning "File location: $ProjectDir\.env"
}
# Create Windows Service scripts
Write-Status "Creating Windows Service scripts..."
# API Server service script
@"
# Start API Server
Set-Location '$ProjectDir'
& '$PythonEnv\Scripts\Activate.ps1'
python main.py
"@ | Out-File -FilePath "start-api.ps1" -Encoding UTF8
# Telegram Bot service script
@"
# Start Telegram Bot
Set-Location '$ProjectDir'
& '$PythonEnv\Scripts\Activate.ps1'
python run_telegram_bot.py
"@ | Out-File -FilePath "start-bot.ps1" -Encoding UTF8
# Install NSSM (Non-Sucking Service Manager) for Windows Services
Write-Status "Installing NSSM for Windows Services..."
choco install nssm -y
# Create Windows Services
Write-Status "Creating Windows Services..."
# Remove existing services if they exist
try {
nssm remove "YouTube-API" confirm
nssm remove "YouTube-Bot" confirm
} catch {
# Services don't exist, that's ok
}
# Create API Server service
nssm install "YouTube-API" powershell.exe
nssm set "YouTube-API" AppParameters "-ExecutionPolicy Bypass -File `"$ProjectDir\start-api.ps1`""
nssm set "YouTube-API" DisplayName "YouTube MCP API Server"
nssm set "YouTube-API" Description "YouTube Metadata Extractor API Server"
nssm set "YouTube-API" Start SERVICE_AUTO_START
# Create Telegram Bot service
nssm install "YouTube-Bot" powershell.exe
nssm set "YouTube-Bot" AppParameters "-ExecutionPolicy Bypass -File `"$ProjectDir\start-bot.ps1`""
nssm set "YouTube-Bot" DisplayName "YouTube Telegram Bot"
nssm set "YouTube-Bot" Description "YouTube Metadata Extractor Telegram Bot"
nssm set "YouTube-Bot" Start SERVICE_AUTO_START
# Configure service dependencies (Bot depends on API)
nssm set "YouTube-Bot" DependOnService "YouTube-API"
# Start services
Write-Status "Starting Windows Services..."
Start-Service "YouTube-API"
Start-Sleep 5
Start-Service "YouTube-Bot"
# Check service status
Write-Status "Checking service status..."
Start-Sleep 5
$apiStatus = Get-Service "YouTube-API" -ErrorAction SilentlyContinue
$botStatus = Get-Service "YouTube-Bot" -ErrorAction SilentlyContinue
if ($apiStatus.Status -eq "Running") {
Write-Status "YouTube API Server is running"
} else {
Write-Error "YouTube API Server failed to start"
Get-Service "YouTube-API" | Format-Table
}
if ($botStatus.Status -eq "Running") {
Write-Status "YouTube Telegram Bot is running"
} else {
Write-Error "YouTube Telegram Bot failed to start"
Get-Service "YouTube-Bot" | Format-Table
}
# Configure Windows Firewall
Write-Status "Configuring Windows Firewall..."
try {
New-NetFirewallRule -DisplayName "YouTube API Server" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
Write-Status "Firewall rule added for port 8080"
} catch {
Write-Warning "Could not add firewall rule. You may need to do this manually."
}
Write-Status "Deployment completed!"
Write-Host ""
Write-Host "π Next steps:" -ForegroundColor Cyan
Write-Host "1. Edit $ProjectDir\.env with your API keys"
Write-Host "2. Restart services: Restart-Service YouTube-API, YouTube-Bot"
Write-Host "3. Check logs in Event Viewer or service logs"
Write-Host ""
Write-Host "π Service URLs:" -ForegroundColor Cyan
Write-Host "- API Server: http://localhost:8080"
Write-Host "- Health Check: http://localhost:8080/health"
Write-Host ""
Write-Host "π± Service Management:" -ForegroundColor Cyan
Write-Host "- Start: Start-Service YouTube-API, YouTube-Bot"
Write-Host "- Stop: Stop-Service YouTube-API, YouTube-Bot"
Write-Host "- Restart: Restart-Service YouTube-API, YouTube-Bot"
Write-Host "- Status: Get-Service YouTube-API, YouTube-Bot"
Write-Host "- Remove: nssm remove YouTube-API confirm; nssm remove YouTube-Bot confirm" |