Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import json
|
| 4 |
+
import requests
|
| 5 |
+
from huggingface_hub import upload_file
|
| 6 |
+
|
| 7 |
+
# === CONFIGURATION ===
|
| 8 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
+
ZEROUPLOAD_TOKEN = "vcIXZnfFfZlPg5GEw4JqeqZTroJh4nst0WqFvun37SNr1wtzwsu6wC9pZ4x8ze4z"
|
| 10 |
+
ZEROUPLOAD_BASE = "https://zeroupload.com/api/v2/file/download"
|
| 11 |
+
REPO_ID = "Fred808/BG1"
|
| 12 |
+
DATA_PATH = "AEffects"
|
| 13 |
+
PROCESSED_FILE = "processed.json"
|
| 14 |
+
OUTPUT_DIR = "batch_downloads"
|
| 15 |
+
|
| 16 |
+
HEADERS = {
|
| 17 |
+
"Authorization": f"Bearer {ZEROUPLOAD_TOKEN}"
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# === YOUR DOWNLOAD LIST ===
|
| 21 |
+
DOWNLOAD_LIST = [
|
| 22 |
+
{"filename": "video1.mp4", "file_id": "abc123"},
|
| 23 |
+
{"filename": "video2.mp4", "file_id": "xyz456"},
|
| 24 |
+
# Add more files here
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# === Load processed files ===
|
| 28 |
+
if os.path.exists(PROCESSED_FILE):
|
| 29 |
+
with open(PROCESSED_FILE, "r") as f:
|
| 30 |
+
processed_ids = set(json.load(f))
|
| 31 |
+
else:
|
| 32 |
+
processed_ids = set()
|
| 33 |
+
|
| 34 |
+
def save_processed():
|
| 35 |
+
with open(PROCESSED_FILE, "w") as f:
|
| 36 |
+
json.dump(list(processed_ids), f, indent=2)
|
| 37 |
+
|
| 38 |
+
def upload_to_dataset(filepath):
|
| 39 |
+
try:
|
| 40 |
+
upload_file(
|
| 41 |
+
path_or_fileobj=filepath,
|
| 42 |
+
path_in_repo=f"{DATA_PATH}/{os.path.basename(filepath)}",
|
| 43 |
+
repo_id=REPO_ID,
|
| 44 |
+
repo_type="dataset",
|
| 45 |
+
token=HF_TOKEN
|
| 46 |
+
)
|
| 47 |
+
print(f"[↑] Uploaded: {filepath}")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
print(f"[!] Upload failed: {filepath} — {e}")
|
| 50 |
+
|
| 51 |
+
# === Create output folder ===
|
| 52 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 53 |
+
|
| 54 |
+
# === Download and upload ===
|
| 55 |
+
for item in DOWNLOAD_LIST:
|
| 56 |
+
filename = item.get("filename")
|
| 57 |
+
file_id = item.get("file_id")
|
| 58 |
+
|
| 59 |
+
if not filename or not file_id:
|
| 60 |
+
print("[!] Skipping invalid entry.")
|
| 61 |
+
continue
|
| 62 |
+
|
| 63 |
+
if file_id in processed_ids:
|
| 64 |
+
print(f"[✔] Already processed: {file_id}")
|
| 65 |
+
continue
|
| 66 |
+
|
| 67 |
+
file_url = f"{ZEROUPLOAD_BASE}/{file_id}"
|
| 68 |
+
local_path = os.path.join(OUTPUT_DIR, filename)
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
print(f"[*] Downloading {filename}...")
|
| 72 |
+
with requests.get(file_url, headers=HEADERS, stream=True) as r:
|
| 73 |
+
r.raise_for_status()
|
| 74 |
+
with open(local_path, "wb") as f:
|
| 75 |
+
for chunk in r.iter_content(chunk_size=8192):
|
| 76 |
+
f.write(chunk)
|
| 77 |
+
print(f"[✓] Downloaded: {filename}")
|
| 78 |
+
|
| 79 |
+
upload_to_dataset(local_path)
|
| 80 |
+
|
| 81 |
+
processed_ids.add(file_id)
|
| 82 |
+
save_processed()
|
| 83 |
+
os.remove(local_path)
|
| 84 |
+
|
| 85 |
+
except Exception as e:
|
| 86 |
+
print(f"[!] Error downloading/uploading {filename}: {e}")
|
| 87 |
+
|
| 88 |
+
time.sleep(2) # small pause between files
|
| 89 |
+
|
| 90 |
+
print("\n✅ Done. All downloads and uploads completed.")
|