Add video upload functionality and .gitignore file
Browse files- .gitignore +44 -0
- main.py +27 -1
.gitignore
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dependencies
|
| 2 |
+
node_modules/
|
| 3 |
+
npm-debug.log
|
| 4 |
+
yarn-debug.log
|
| 5 |
+
yarn-error.log
|
| 6 |
+
package-lock.json
|
| 7 |
+
yarn.lock
|
| 8 |
+
|
| 9 |
+
# Environment variables
|
| 10 |
+
.env
|
| 11 |
+
.env.local
|
| 12 |
+
.env.development.local
|
| 13 |
+
.env.test.local
|
| 14 |
+
.env.production.local
|
| 15 |
+
|
| 16 |
+
# Build output
|
| 17 |
+
dist/
|
| 18 |
+
build/
|
| 19 |
+
out/
|
| 20 |
+
|
| 21 |
+
# Logs
|
| 22 |
+
logs/
|
| 23 |
+
*.log
|
| 24 |
+
|
| 25 |
+
# Coverage directory used by tools like istanbul
|
| 26 |
+
coverage/
|
| 27 |
+
|
| 28 |
+
# IDE and editor files
|
| 29 |
+
.idea/
|
| 30 |
+
.vscode/
|
| 31 |
+
*.swp
|
| 32 |
+
*.swo
|
| 33 |
+
.DS_Store
|
| 34 |
+
|
| 35 |
+
# Temporary files
|
| 36 |
+
tmp/
|
| 37 |
+
temp/
|
| 38 |
+
|
| 39 |
+
# Uploads
|
| 40 |
+
uploads/
|
| 41 |
+
|
| 42 |
+
# Python
|
| 43 |
+
__pycache__/
|
| 44 |
+
*.pyc
|
main.py
CHANGED
|
@@ -1,16 +1,18 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
from pydantic import BaseModel, HttpUrl
|
|
|
|
| 4 |
from typing import List
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
import uuid
|
| 8 |
import aiohttp
|
| 9 |
import re
|
| 10 |
-
from urllib.parse import urlparse
|
| 11 |
import shutil
|
| 12 |
import aiofiles
|
| 13 |
|
|
|
|
|
|
|
| 14 |
# Create FastAPI app
|
| 15 |
app = FastAPI()
|
| 16 |
|
|
@@ -55,6 +57,30 @@ async def download_file(url, local_path):
|
|
| 55 |
print(f"Error downloading {url}: {str(e)}")
|
| 56 |
return False
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):
|
| 59 |
"""Generate slideshow from images and audio using ffmpeg asynchronously"""
|
| 60 |
# Create temporary file list for ffmpeg concat (used in non-zoom mode)
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
from pydantic import BaseModel, HttpUrl
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
from typing import List
|
| 6 |
import os
|
| 7 |
import asyncio
|
| 8 |
import uuid
|
| 9 |
import aiohttp
|
| 10 |
import re
|
|
|
|
| 11 |
import shutil
|
| 12 |
import aiofiles
|
| 13 |
|
| 14 |
+
load_dotenv()
|
| 15 |
+
|
| 16 |
# Create FastAPI app
|
| 17 |
app = FastAPI()
|
| 18 |
|
|
|
|
| 57 |
print(f"Error downloading {url}: {str(e)}")
|
| 58 |
return False
|
| 59 |
|
| 60 |
+
async def upload_video(url):
|
| 61 |
+
"""Upload a video and return the upload URL"""
|
| 62 |
+
try:
|
| 63 |
+
data = {
|
| 64 |
+
'file': str(url),
|
| 65 |
+
'upload_preset': 'video-input-production',
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
async with aiohttp.ClientSession() as session:
|
| 69 |
+
async with session.post(
|
| 70 |
+
os.getenv("VIDEO_UPLOAD_URL"),
|
| 71 |
+
data=data
|
| 72 |
+
) as response:
|
| 73 |
+
if response.status != 200:
|
| 74 |
+
print(f"Upload failed with status {response.status}")
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
result = await response.json()
|
| 78 |
+
return result.get('secure_url')
|
| 79 |
+
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Error uploading video: {str(e)}")
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=False, zoom_ratio=0.04):
|
| 85 |
"""Generate slideshow from images and audio using ffmpeg asynchronously"""
|
| 86 |
# Create temporary file list for ffmpeg concat (used in non-zoom mode)
|