-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
Β·216 lines (183 loc) Β· 6.21 KB
/
setup.py
File metadata and controls
executable file
Β·216 lines (183 loc) Β· 6.21 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python3
"""
ShortsCreator Setup and Validation Script
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def check_python_version():
"""Check if Python version is 3.8+"""
print("π Checking Python version...")
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print(f"β Python 3.8+ required, found {version.major}.{version.minor}")
return False
print(f"β
Python {version.major}.{version.minor}.{version.micro} OK")
return True
def check_ffmpeg():
"""Check if FFmpeg is installed"""
print("π¬ Checking FFmpeg...")
if shutil.which('ffmpeg') is None:
print("β FFmpeg not found. Install with:")
print(" macOS: brew install ffmpeg")
print(" Ubuntu: sudo apt-get install ffmpeg")
print(" Windows: Download from https://ffmpeg.org/")
return False
print("β
FFmpeg found")
return True
def check_docker():
"""Check if Docker is installed"""
print("π³ Checking Docker...")
if shutil.which('docker') is None:
print("β οΈ Docker not found (optional for containerized deployment)")
return False
print("β
Docker found")
return True
def create_directories():
"""Create necessary directories"""
print("π Creating directories...")
directories = ['temp', 'uploads', 'jobs', 'static']
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"β
{directory}/ created")
def create_virtual_environment():
"""Create Python virtual environment"""
print("π§ Setting up virtual environment...")
if not Path('venv').exists():
subprocess.run([sys.executable, '-m', 'venv', 'venv'], check=True)
print("β
Virtual environment created")
else:
print("β
Virtual environment already exists")
def install_dependencies():
"""Install Python dependencies"""
print("π¦ Installing dependencies...")
# Determine the correct pip path
if os.name == 'nt': # Windows
pip_path = 'venv/Scripts/pip'
python_path = 'venv/Scripts/python'
else: # Unix/Linux/macOS
pip_path = 'venv/bin/pip'
python_path = 'venv/bin/python'
try:
# Upgrade pip
subprocess.run([python_path, '-m', 'pip', 'install', '--upgrade', 'pip'],
check=True, capture_output=True)
# Install requirements
subprocess.run([pip_path, 'install', '-r', 'requirements.txt'],
check=True, capture_output=True)
print("β
Dependencies installed")
return True
except subprocess.CalledProcessError as e:
print(f"β Failed to install dependencies: {e}")
return False
def validate_project_structure():
"""Validate project structure"""
print("π Validating project structure...")
required_files = [
'app.py',
'requirements.txt',
'Dockerfile',
'docker-compose.yml',
'app/services/video_service.py',
'app/services/subtitle_service.py',
'app/services/job_manager.py',
'app/utils/download_utils.py'
]
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
if missing_files:
print("β Missing files:")
for file_path in missing_files:
print(f" - {file_path}")
return False
print("β
Project structure valid")
return True
def run_basic_tests():
"""Run basic import tests"""
print("π§ͺ Running basic tests...")
# Determine the correct python path
if os.name == 'nt': # Windows
python_path = 'venv/Scripts/python'
else: # Unix/Linux/macOS
python_path = 'venv/bin/python'
test_code = """
import sys
sys.path.insert(0, '.')
try:
from app.services.video_service import VideoService
from app.services.subtitle_service import SubtitleService
from app.services.job_manager import JobManager
from app.utils.download_utils import download_file
import flask
import moviepy
print("β
All imports successful")
except ImportError as e:
print(f"β Import error: {e}")
sys.exit(1)
"""
try:
result = subprocess.run([python_path, '-c', test_code],
capture_output=True, text=True, check=True)
print(result.stdout.strip())
return True
except subprocess.CalledProcessError as e:
print(f"β Test failed: {e.stderr}")
return False
def show_next_steps():
"""Show next steps after successful setup"""
print("\nπ Setup Complete!")
print("=" * 50)
print("Next steps:")
print("")
print("1. Start the API server:")
print(" ./start.sh")
print(" OR manually:")
print(" source venv/bin/activate # On Windows: venv\\Scripts\\activate")
print(" python app.py")
print("")
print("2. Test the API:")
print(" python test_api.py")
print("")
print("3. View examples:")
print(" python examples.py")
print("")
print("4. Docker deployment:")
print(" docker-compose up --build")
print(" OR")
print(" ./deploy.sh")
print("")
print("π API will be available at: http://localhost:5000")
print("π Health check: http://localhost:5000/health")
def main():
"""Run setup process"""
print("π¬ ShortsCreator Setup")
print("=" * 30)
checks_passed = True
# Run checks
if not check_python_version():
checks_passed = False
if not check_ffmpeg():
checks_passed = False
check_docker() # Optional
if not validate_project_structure():
checks_passed = False
if not checks_passed:
print("\nβ Setup failed. Please fix the issues above.")
return 1
# Setup steps
create_directories()
create_virtual_environment()
if not install_dependencies():
print("\nβ Failed to install dependencies.")
return 1
if not run_basic_tests():
print("\nβ Basic tests failed.")
return 1
show_next_steps()
return 0
if __name__ == "__main__":
sys.exit(main())