Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
5enox committed Jul 10, 2024
1 parent 977e013 commit 51d8a88
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 89 deletions.
46 changes: 0 additions & 46 deletions default.conf

This file was deleted.

8 changes: 4 additions & 4 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def download_file(self, url: str) -> Optional[list]:
print(f"Failed to download video from {url}: {e}")
return None

def adjust(self, video_path: str, saturation: float) -> Union[bool, None]:
def adjust(self, video_path: str, saturation: float) -> Union[bool, None, str]:
try:
# Check if ffmpeg is installed
try:
Expand Down Expand Up @@ -102,11 +102,11 @@ def adjust(self, video_path: str, saturation: float) -> Union[bool, None]:
return True

except ffmpeg.Error as e:
print(f"FFmpeg error: {e}")
return f"FFmpeg error: {e}"
except Exception as e:
print(f"An error occurred: {e}")
return f"An error occurred: {e}"

return None
return "Error in adjusting the video"


class TikTokDownloader(VideoDownloader):
Expand Down
81 changes: 81 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Download Form</title>
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
}

label {
margin-top: 10px;
}

input {
margin-bottom: 10px;
}

.loading {
display: none;
margin-top: 20px;
}

.loading.show {
display: block;
}
</style>
</head>
<body>
<div class="container">
<form id="videoForm">
<label for="videoLink">Video Link:</label>
<input type="url" id="videoLink" name="videoLink" required>
<label for="saturation">Saturation:</label>
<input type="number" id="saturation" name="saturation" step="0.01" required>
<button type="submit">Submit</button>
</form>
<div id="loading" class="loading" hidden>Loading...</div>
<div id="result" hidden>
<a id="downloadButton" href="#" download>Download Video</a>
</div>
</div>
<script>
document.getElementById('videoForm').addEventListener('submit', async function (e) {
e.preventDefault();

const videoLink = encodeURIComponent(document.getElementById('videoLink').value);
const saturation = encodeURIComponent(document.getElementById('saturation').value);
const loadingIndicator = document.getElementById('loading');
const resultContainer = document.getElementById('result');
const downloadButton = document.getElementById('downloadButton');

loadingIndicator.classList.add('show');
resultContainer.hidden = true;

try {
const response = await fetch(`https://souqzone.xyz/download-video/?video_url=${videoLink}&saturation=${saturation}`);

if (!response.ok) {
throw new Error('Network response was not ok');
}

const data = await response.json();
const downloadUrl = data.url; // Adjust this based on the actual JSON response structure

downloadButton.setAttribute('href', downloadUrl);

loadingIndicator.classList.remove('show');
resultContainer.hidden = false;
} catch (error) {
console.error('Error:', error);
loadingIndicator.classList.remove('show');
}
});
</script>
</body>
</html>
37 changes: 35 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@
from sysconfig import get_platform
import threading
import time
import urllib.parse as parse

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from downloader import TikTokDownloader, InstagramDownloader
from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pathlib import Path


app = FastAPI()

origins = [
"https://www.phantomclip.com/" # Replace with your allowed domain
, "https://phantomclip.com/"
]

# Define the CORS policy
app.add_middleware(
CORSMiddleware,
allow_origins='*',
allow_methods=["GET", "POST"], # Add more HTTP methods as needed
allow_headers=["*"], # You can also specify headers explicitly
)


# Defining the directory where downloaded videos will be stored
files_directory = Path("videos")
Expand Down Expand Up @@ -78,11 +94,20 @@ def construct_download_link(filename: str) -> str:
"""
# Remove the last 4 characters (".mp4") from the download link
download_link = filename[:-4]
server_address = "http://178.128.198.151"
server_address = "https://souqzone.xyz"

return f"{server_address}/download?key={download_link}"


def clean_url(video_url: str) -> str:
"""
Function to clean the video URL by decoding URL encoding and replacing special characters.
"""
decoded_url = parse.unquote(video_url)
cleaned_url = decoded_url.replace('%3A', ':').replace('%2F', '/')
return cleaned_url


@ app.get("/download-video/", response_model=VideoDownloadResponse)
async def download_video(video_url: str, saturation: float = 1.05):
try:
Expand All @@ -95,6 +120,7 @@ async def download_video(video_url: str, saturation: float = 1.05):
raise HTTPException(status_code=400, detail="Unsupported platform")

# Get the video download URL
video_url = clean_url(video_url)
download_url = downloader.get_download_url(video_url)

if not download_url:
Expand Down Expand Up @@ -131,4 +157,11 @@ async def download_file(key: str):
file_path = files_directory / (key + ".mp4")
if not file_path.exists():
raise HTTPException(status_code=404, detail="File not found")
return FileResponse(path=file_path, filename=key, media_type="video/mp4")
return FileResponse(
path=file_path,
filename=key + ".mp4",
media_type="video/mp4",
headers={
"Content-Disposition": f"attachment; filename={key}.mp4"
}
)
56 changes: 19 additions & 37 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# nginx.conf

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name 157.230.29.110; # Adjust this based on your domain name
server_name souqzone.xyz; # Adjust this based on your domain name

location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name souqzone.xyz; # Adjust this based on your domain name

ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;

location / {
proxy_pass http://157.230.29.110:8000/; # Adjust this based on your backend service
Expand All @@ -29,25 +45,6 @@ http {
























# events {
Expand All @@ -57,25 +54,10 @@ http {
# http {
# server {
# listen 80;
# server_name 157.230.29.110; # Adjust this based on your domain name

# location / {
# return 301 https://$host$request_uri;
# }
# }

# server {
# listen 443 ssl;
# server_name 157.230.29.110; # Adjust this based on your domain name

# ssl_certificate /etc/ssl/certs/server.crt;
# ssl_certificate_key /etc/ssl/private/server.key;

# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers HIGH:!aNULL:!MD5;
# server_name 164.90.190.221; # Adjust this based on your domain name

# location / {
# proxy_pass http://157.230.29.110:8000/; # Adjust this based on your backend service
# proxy_pass http://164.90.190.221:8000/; # Adjust this based on your backend service
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ requests
wget
ffmpeg-python
moviepy
starlette

0 comments on commit 51d8a88

Please sign in to comment.