Spaces:
Paused
Paused
Commit
Β·
cab34ab
1
Parent(s):
4a0702d
modify vedio_upload_to_gofile.py
Browse files- vedio_upload_to_gofile.py +33 -17
vedio_upload_to_gofile.py
CHANGED
|
@@ -1,44 +1,60 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import shutil
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import ImportantVariables
|
| 6 |
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
# Compress the folder into a ZIP file
|
| 10 |
-
print("Compress the folder into a ZIP file")
|
| 11 |
-
zip_path = f"{zip_name}"
|
| 12 |
-
shutil.make_archive(zip_path.replace(".zip", ""), 'zip', folder_path)
|
| 13 |
-
|
| 14 |
-
# Upload the ZIP file to Gofile
|
| 15 |
-
print("Upload the ZIP file to Gofile")
|
| 16 |
url = "https://store1.gofile.io/uploadFile"
|
| 17 |
-
with open(
|
| 18 |
response = requests.post(url, files={"file": f})
|
| 19 |
|
| 20 |
-
# Handle response
|
| 21 |
if response.status_code == 200:
|
| 22 |
result = response.json()
|
| 23 |
if result["status"] == "ok":
|
| 24 |
-
|
| 25 |
-
print(f"β
Folder uploaded: {public_url}")
|
| 26 |
-
# Cleanup: Remove the ZIP file after upload
|
| 27 |
-
os.remove(zip_path)
|
| 28 |
-
return public_url
|
| 29 |
else:
|
| 30 |
print("β Upload failed:", result)
|
| 31 |
else:
|
| 32 |
print(f"β Error: HTTP {response.status_code}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
def main():
|
| 39 |
# Example usage
|
| 40 |
folder_path = ImportantVariables.PATHS["output_folder_path"]
|
| 41 |
public_url=upload_folder_to_gofile(folder_path)
|
|
|
|
| 42 |
return public_url
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
import ImportantVariables
|
| 6 |
|
| 7 |
|
| 8 |
+
def upload_file_to_gofile(file_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
url = "https://store1.gofile.io/uploadFile"
|
| 10 |
+
with open(file_path, "rb") as f:
|
| 11 |
response = requests.post(url, files={"file": f})
|
| 12 |
|
|
|
|
| 13 |
if response.status_code == 200:
|
| 14 |
result = response.json()
|
| 15 |
if result["status"] == "ok":
|
| 16 |
+
return result["data"]["downloadPage"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
print("β Upload failed:", result)
|
| 19 |
else:
|
| 20 |
print(f"β Error: HTTP {response.status_code}")
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def upload_folder_to_gofile(folder_path, json_name="files.json"):
|
| 25 |
+
file_urls = {}
|
| 26 |
+
|
| 27 |
+
# Upload each file in the folder
|
| 28 |
+
for root, _, files in os.walk(folder_path):
|
| 29 |
+
for file in files:
|
| 30 |
+
file_path = os.path.join(root, file)
|
| 31 |
+
print(f"Uploading {file}...")
|
| 32 |
+
file_url = upload_file_to_gofile(file_path)
|
| 33 |
+
if file_url:
|
| 34 |
+
file_urls[file] = file_url
|
| 35 |
+
|
| 36 |
+
# Save file URLs in a JSON file
|
| 37 |
+
json_path = os.path.join(folder_path, json_name)
|
| 38 |
+
with open(json_path, "w") as json_file:
|
| 39 |
+
json.dump(file_urls, json_file, indent=4)
|
| 40 |
+
|
| 41 |
+
# Upload the JSON file
|
| 42 |
+
print("Uploading JSON file...")
|
| 43 |
+
json_file_url = upload_file_to_gofile(json_path)
|
| 44 |
|
| 45 |
+
return json_file_url
|
| 46 |
|
| 47 |
|
| 48 |
+
# Example usage
|
| 49 |
+
# folder_url = upload_folder_to_gofile("your_folder_path_here")
|
| 50 |
+
# print("JSON file URL:", folder_url)
|
| 51 |
|
| 52 |
|
| 53 |
def main():
|
| 54 |
# Example usage
|
| 55 |
folder_path = ImportantVariables.PATHS["output_folder_path"]
|
| 56 |
public_url=upload_folder_to_gofile(folder_path)
|
| 57 |
+
print("JSON file URL:", public_url)
|
| 58 |
return public_url
|
| 59 |
|
| 60 |
|