Spaces:
Sleeping
Sleeping
Upload cloud_download.py
Browse files- cloud_download.py +36 -9
cloud_download.py
CHANGED
|
@@ -1,18 +1,45 @@
|
|
| 1 |
import cloudinary.api
|
| 2 |
|
| 3 |
# Assuming you have already configured Cloudinary with your credentials
|
| 4 |
-
cloudinary.config(
|
| 5 |
-
cloud_name = "djepbidi1",
|
| 6 |
-
api_key = "531731913696587",
|
| 7 |
-
api_secret = "_5ePxVQEECYYOukhSroYXq7eKL0"
|
| 8 |
-
)
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Fetch the asset's details
|
| 13 |
-
asset_details = cloudinary.api.resource(public_id, resource_type='video')
|
| 14 |
|
| 15 |
# Extract the secure URL of the asset
|
| 16 |
-
asset_url = asset_details.get('secure_url')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
| 1 |
import cloudinary.api
|
| 2 |
|
| 3 |
# Assuming you have already configured Cloudinary with your credentials
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def download_file():
|
| 6 |
+
cloudinary.config(
|
| 7 |
+
cloud_name = "djepbidi1",
|
| 8 |
+
api_key = "531731913696587",
|
| 9 |
+
api_secret = "_5ePxVQEECYYOukhSroYXq7eKL0"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
public_id = 'test'
|
| 13 |
|
| 14 |
# Fetch the asset's details
|
| 15 |
+
asset_details = cloudinary.api.resource(public_id, resource_type='video')
|
| 16 |
|
| 17 |
# Extract the secure URL of the asset
|
| 18 |
+
asset_url = asset_details.get('secure_url')
|
| 19 |
+
|
| 20 |
+
print("Asset URL:", asset_url)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
"""
|
| 24 |
+
Download a file from a given URL and save it to the specified local path.
|
| 25 |
+
|
| 26 |
+
Parameters:
|
| 27 |
+
- url: The URL of the file to download.
|
| 28 |
+
- save_path: The local path where the file should be saved.
|
| 29 |
+
"""
|
| 30 |
+
response = requests.get(asset_url, stream=True)
|
| 31 |
+
|
| 32 |
+
# Check if the request was successful
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
with open(save_path, 'wb') as f:
|
| 35 |
+
for chunk in response.iter_content(chunk_size=128):
|
| 36 |
+
f.write(chunk)
|
| 37 |
+
print(f"File downloaded successfully: {save_path}")
|
| 38 |
+
else:
|
| 39 |
+
print(f"Failed to download file. Status code: {response.status_code}")
|
| 40 |
+
|
| 41 |
+
# Example usage
|
| 42 |
+
#cloudinary_url = "YOUR_CLOUDINARY_FILE_URL"
|
| 43 |
+
local_save_path = "downloaded.mp3"
|
| 44 |
|
| 45 |
+
download_file()
|