Update main.py
Browse files
main.py
CHANGED
|
@@ -3,11 +3,11 @@ 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"
|
|
@@ -17,23 +17,23 @@ HEADERS = {
|
|
| 17 |
"Authorization": f"Bearer {ZEROUPLOAD_TOKEN}"
|
| 18 |
}
|
| 19 |
|
| 20 |
-
# ===
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
# Add more
|
| 25 |
]
|
| 26 |
|
| 27 |
-
# === Load processed
|
| 28 |
if os.path.exists(PROCESSED_FILE):
|
| 29 |
with open(PROCESSED_FILE, "r") as f:
|
| 30 |
-
|
| 31 |
else:
|
| 32 |
-
|
| 33 |
|
| 34 |
def save_processed():
|
| 35 |
with open(PROCESSED_FILE, "w") as f:
|
| 36 |
-
json.dump(list(
|
| 37 |
|
| 38 |
def upload_to_dataset(filepath):
|
| 39 |
try:
|
|
@@ -48,43 +48,43 @@ def upload_to_dataset(filepath):
|
|
| 48 |
except Exception as e:
|
| 49 |
print(f"[!] Upload failed: {filepath} — {e}")
|
| 50 |
|
| 51 |
-
# ===
|
| 52 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 53 |
|
| 54 |
-
# ===
|
| 55 |
-
for
|
| 56 |
-
|
| 57 |
-
|
| 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"[*]
|
| 72 |
-
with requests.get(
|
| 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
|
| 87 |
|
| 88 |
-
time.sleep(2)
|
| 89 |
|
| 90 |
-
print("\n✅
|
|
|
|
| 3 |
import json
|
| 4 |
import requests
|
| 5 |
from huggingface_hub import upload_file
|
| 6 |
+
from urllib.parse import urlparse
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 10 |
ZEROUPLOAD_TOKEN = "vcIXZnfFfZlPg5GEw4JqeqZTroJh4nst0WqFvun37SNr1wtzwsu6wC9pZ4x8ze4z"
|
|
|
|
| 11 |
REPO_ID = "Fred808/BG1"
|
| 12 |
DATA_PATH = "AEffects"
|
| 13 |
PROCESSED_FILE = "processed.json"
|
|
|
|
| 17 |
"Authorization": f"Bearer {ZEROUPLOAD_TOKEN}"
|
| 18 |
}
|
| 19 |
|
| 20 |
+
# === Only list of ZeroUpload URLs ===
|
| 21 |
+
DOWNLOAD_URLS = [
|
| 22 |
+
"https://zeroupload.com/e7a5f338b6db8987f1735378ad164c79",
|
| 23 |
+
"https://zeroupload.com/91d9a79cc6cf4ae1a3fb15c16a062fb4",
|
| 24 |
+
# Add more...
|
| 25 |
]
|
| 26 |
|
| 27 |
+
# === Load processed ===
|
| 28 |
if os.path.exists(PROCESSED_FILE):
|
| 29 |
with open(PROCESSED_FILE, "r") as f:
|
| 30 |
+
processed_urls = set(json.load(f))
|
| 31 |
else:
|
| 32 |
+
processed_urls = set()
|
| 33 |
|
| 34 |
def save_processed():
|
| 35 |
with open(PROCESSED_FILE, "w") as f:
|
| 36 |
+
json.dump(list(processed_urls), f, indent=2)
|
| 37 |
|
| 38 |
def upload_to_dataset(filepath):
|
| 39 |
try:
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
print(f"[!] Upload failed: {filepath} — {e}")
|
| 50 |
|
| 51 |
+
# === Prepare output directory ===
|
| 52 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 53 |
|
| 54 |
+
# === Main loop ===
|
| 55 |
+
for url in DOWNLOAD_URLS:
|
| 56 |
+
if url in processed_urls:
|
| 57 |
+
print(f"[✔] Already processed: {url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
continue
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
try:
|
| 61 |
+
print(f"[*] Requesting: {url}")
|
| 62 |
+
with requests.get(url, headers=HEADERS, stream=True) as r:
|
| 63 |
r.raise_for_status()
|
| 64 |
+
|
| 65 |
+
# Try to extract filename from headers, fallback to last URL segment
|
| 66 |
+
cd = r.headers.get("content-disposition")
|
| 67 |
+
if cd and "filename=" in cd:
|
| 68 |
+
filename = cd.split("filename=")[1].strip('"')
|
| 69 |
+
else:
|
| 70 |
+
filename = os.path.basename(urlparse(url).path) + ".mp4"
|
| 71 |
+
|
| 72 |
+
local_path = os.path.join(OUTPUT_DIR, filename)
|
| 73 |
+
|
| 74 |
with open(local_path, "wb") as f:
|
| 75 |
for chunk in r.iter_content(chunk_size=8192):
|
| 76 |
f.write(chunk)
|
| 77 |
+
|
| 78 |
print(f"[✓] Downloaded: {filename}")
|
| 79 |
|
| 80 |
upload_to_dataset(local_path)
|
| 81 |
+
processed_urls.add(url)
|
|
|
|
| 82 |
save_processed()
|
| 83 |
os.remove(local_path)
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
+
print(f"[!] Error with {url}: {e}")
|
| 87 |
|
| 88 |
+
time.sleep(2)
|
| 89 |
|
| 90 |
+
print("\n✅ All ZeroUpload files processed.")
|