Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
from typing import List
|
9 |
import logging
|
10 |
import urllib3
|
|
|
11 |
|
12 |
# Suppress only the single InsecureRequestWarning
|
13 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
@@ -23,6 +24,22 @@ class VideoURLs(BaseModel):
|
|
23 |
|
24 |
MAX_VIDEOS = 10
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def download_video(url):
|
27 |
try:
|
28 |
response = requests.get(url, verify=False, timeout=30)
|
@@ -83,12 +100,37 @@ def combine_videos(urls):
|
|
83 |
logger.error(f"Error combining videos: {str(e)}")
|
84 |
raise HTTPException(status_code=500, detail=f"Error combining videos: {str(e)}")
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
@app.post("/combine_videos")
|
87 |
async def process_urls(video_urls: VideoURLs):
|
88 |
try:
|
89 |
-
|
90 |
-
if
|
91 |
-
|
|
|
|
|
92 |
else:
|
93 |
raise HTTPException(status_code=400, detail="Failed to combine videos")
|
94 |
except HTTPException as he:
|
|
|
8 |
from typing import List
|
9 |
import logging
|
10 |
import urllib3
|
11 |
+
import vimeo
|
12 |
|
13 |
# Suppress only the single InsecureRequestWarning
|
14 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
24 |
|
25 |
MAX_VIDEOS = 10
|
26 |
|
27 |
+
'''
|
28 |
+
# Vimeo client setup
|
29 |
+
client = vimeo.VimeoClient(
|
30 |
+
token='6c0e53613726874a46da7c0f286e27b5',
|
31 |
+
key='45dc18a3c7bdb1dc6255a49d784398b14b4fd55f',
|
32 |
+
secret='jVwFHFHWs0pGs0rdlHzCnDvkJFru1IeNACt0ygV9bk3mMU45hzZGvg/I+vTzzzvpU1HakvxdxITzf/gokrq5k8VPwQmGirosmltJZAf9/CIAnPpKw19lGrr13MKXKQ1m'
|
33 |
+
)
|
34 |
+
'''
|
35 |
+
|
36 |
+
# Vimeo client setup
|
37 |
+
client = vimeo.VimeoClient(
|
38 |
+
token='35b24d71f540bfa24e61d488cf34e457',
|
39 |
+
key='9efa7b1c1827ce4b1d74330d0a90cf62ff4da8b9',
|
40 |
+
secret='QIwoszSklYElk2wH5PHqe/EzSDB8HM+gdHBg4iaiDs2SkYa+RS3T4ei/VrPWGMMZt2qGXYIbjxfNlPYOtz5g3Ylsys0VpBuiUjkRhz+oR6yR2epl/MW68V1ZxS/D7EwD'
|
41 |
+
)
|
42 |
+
|
43 |
def download_video(url):
|
44 |
try:
|
45 |
response = requests.get(url, verify=False, timeout=30)
|
|
|
100 |
logger.error(f"Error combining videos: {str(e)}")
|
101 |
raise HTTPException(status_code=500, detail=f"Error combining videos: {str(e)}")
|
102 |
|
103 |
+
def upload_to_vimeo(video_path):
|
104 |
+
try:
|
105 |
+
# Upload the video to Vimeo
|
106 |
+
uri = client.upload(video_path, data={
|
107 |
+
'name': 'Combined Video',
|
108 |
+
'description': 'This video was combined using our app.'
|
109 |
+
})
|
110 |
+
|
111 |
+
# Get the Vimeo URL
|
112 |
+
response = client.get(uri + '?fields=link').json()
|
113 |
+
vimeo_url = response['link']
|
114 |
+
|
115 |
+
return vimeo_url
|
116 |
+
except vimeo.exceptions.VideoUploadFailure as e:
|
117 |
+
logger.error(f"Video upload failed: {str(e)}")
|
118 |
+
raise HTTPException(status_code=500, detail=f"Failed to upload to Vimeo: {str(e)}")
|
119 |
+
except vimeo.exceptions.APIRateLimitExceededFailure:
|
120 |
+
logger.error("API rate limit exceeded")
|
121 |
+
raise HTTPException(status_code=429, detail="API rate limit exceeded. Please try again later.")
|
122 |
+
except Exception as e:
|
123 |
+
logger.error(f"Unexpected error during Vimeo upload: {str(e)}")
|
124 |
+
raise HTTPException(status_code=500, detail=f"Failed to upload to Vimeo: {str(e)}")
|
125 |
+
|
126 |
@app.post("/combine_videos")
|
127 |
async def process_urls(video_urls: VideoURLs):
|
128 |
try:
|
129 |
+
combined_video_path = combine_videos(video_urls.urls)
|
130 |
+
if combined_video_path:
|
131 |
+
vimeo_url = upload_to_vimeo(combined_video_path)
|
132 |
+
os.remove(combined_video_path) # Clean up the local file
|
133 |
+
return {"vimeo_url": vimeo_url}
|
134 |
else:
|
135 |
raise HTTPException(status_code=400, detail="Failed to combine videos")
|
136 |
except HTTPException as he:
|