Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -44,11 +44,17 @@ def get_aspect_ratio(input_path, aspect_ratio):
|
|
44 |
return f"{video.size[0]}:{video.size[1]}"
|
45 |
|
46 |
def upload_to_web3_storage(api_key, path):
|
47 |
-
"""Uploads a file to web3.storage."""
|
|
|
48 |
with open(path, 'rb') as f:
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload):
|
54 |
"""Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
|
|
|
44 |
return f"{video.size[0]}:{video.size[1]}"
|
45 |
|
46 |
def upload_to_web3_storage(api_key, path):
|
47 |
+
"""Uploads a file to web3.storage using the HTTP API."""
|
48 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
49 |
with open(path, 'rb') as f:
|
50 |
+
response = requests.post(
|
51 |
+
"https://api.web3.storage/upload",
|
52 |
+
headers=headers,
|
53 |
+
data=f,
|
54 |
+
)
|
55 |
+
response.raise_for_status() # Raises an exception if the request failed
|
56 |
+
cid = response.json()["value"]["cid"]
|
57 |
+
return f"https://dweb.link/ipfs/{cid}"
|
58 |
|
59 |
def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload):
|
60 |
"""Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
|