Update main.py
Browse files
main.py
CHANGED
|
@@ -1,35 +1,24 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
-
import json
|
| 4 |
import requests
|
| 5 |
from urllib.parse import urlparse
|
|
|
|
| 6 |
from huggingface_hub import upload_file
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN") # Set this via environment or replace with string
|
| 10 |
-
ZEROUPLOAD_TOKEN = "vcIXZnfFfZlPg5GEw4JqeqZTroJh4nst0WqFvun37SNr1wtzwsu6wC9pZ4x8ze4z"
|
| 11 |
REPO_ID = "Fred808/BG1"
|
| 12 |
DATA_PATH = "AEffects"
|
| 13 |
-
PROCESSED_FILE = "processed.json"
|
| 14 |
OUTPUT_DIR = "batch_downloads"
|
|
|
|
|
|
|
| 15 |
DOWNLOAD_URLS = [
|
| 16 |
-
"https://zeroupload.
|
|
|
|
| 17 |
]
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
# === Load processed list ===
|
| 24 |
-
if os.path.exists(PROCESSED_FILE):
|
| 25 |
-
with open(PROCESSED_FILE, "r") as f:
|
| 26 |
-
processed_urls = set(json.load(f))
|
| 27 |
-
else:
|
| 28 |
-
processed_urls = set()
|
| 29 |
-
|
| 30 |
-
def save_processed():
|
| 31 |
-
with open(PROCESSED_FILE, "w") as f:
|
| 32 |
-
json.dump(list(processed_urls), f, indent=2)
|
| 33 |
|
| 34 |
def upload_to_dataset(filepath):
|
| 35 |
try:
|
|
@@ -44,52 +33,34 @@ def upload_to_dataset(filepath):
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"[!] Upload failed: {filepath} — {e}")
|
| 46 |
|
| 47 |
-
# === Prepare output folder ===
|
| 48 |
-
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 49 |
-
|
| 50 |
# === Start Download Loop ===
|
| 51 |
-
for
|
| 52 |
-
if url in processed_urls:
|
| 53 |
-
print(f"[✔] Already processed: {url}")
|
| 54 |
-
continue
|
| 55 |
-
|
| 56 |
print(f"\n[*] Waiting 12 seconds before next download...")
|
| 57 |
time.sleep(12)
|
| 58 |
|
| 59 |
try:
|
| 60 |
-
print(f"[*] Downloading from: {
|
| 61 |
-
with requests.get(url, headers=HEADERS, stream=True) as r:
|
| 62 |
-
r.raise_for_status()
|
| 63 |
-
|
| 64 |
-
content_type = r.headers.get("Content-Type", "").lower()
|
| 65 |
-
if "html" in content_type:
|
| 66 |
-
raise Exception(f"[!] HTML page received instead of a file. Content-Type: {content_type}")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
else:
|
| 73 |
-
# Fallback to last part of the URL
|
| 74 |
-
filename = os.path.basename(urlparse(url).path)
|
| 75 |
-
if '.' not in filename:
|
| 76 |
-
filename += ".bin"
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
| 81 |
with open(local_path, "wb") as f:
|
| 82 |
for chunk in r.iter_content(chunk_size=8192):
|
| 83 |
f.write(chunk)
|
| 84 |
|
| 85 |
print(f"[✓] Downloaded: {filename}")
|
| 86 |
-
|
| 87 |
upload_to_dataset(local_path)
|
| 88 |
-
processed_urls.add(url)
|
| 89 |
-
save_processed()
|
| 90 |
os.remove(local_path)
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
-
print(f"[!] Error with {
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
print("\n✅ All files processed.")
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
|
|
|
| 3 |
import requests
|
| 4 |
from urllib.parse import urlparse
|
| 5 |
+
from bs4 import BeautifulSoup
|
| 6 |
from huggingface_hub import upload_file
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN") # Set this via environment or replace with string
|
|
|
|
| 10 |
REPO_ID = "Fred808/BG1"
|
| 11 |
DATA_PATH = "AEffects"
|
|
|
|
| 12 |
OUTPUT_DIR = "batch_downloads"
|
| 13 |
+
|
| 14 |
+
# Use the direct download URL provided by the user
|
| 15 |
DOWNLOAD_URLS = [
|
| 16 |
+
"https://ww7.zeroupload.xyz/4642fd002fd25380de2ec0ea980c8bbe/After_Effects_Masterclass_Unleash_Your_Creative_Power!.zip?download_token=53f9ef43d6ad9f6eb9ed63d82b907919a99125e2116abff7d3266cdf8e12a0ee",
|
| 17 |
+
"https://ww3.zeroupload.xyz/e7a5f338b6db8987f1735378ad164c79/CGCookie_-_Blender_4.2_Core_Essentials_-_9_Tutorials.7z.003?download_token=1adf44bc722babae998608712c4704e6f7a747e641a9e09d913e2e992635ad9f"
|
| 18 |
]
|
| 19 |
|
| 20 |
+
# === Prepare output folder ===
|
| 21 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def upload_to_dataset(filepath):
|
| 24 |
try:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
print(f"[!] Upload failed: {filepath} — {e}")
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
# === Start Download Loop ===
|
| 37 |
+
for direct_download_link in DOWNLOAD_URLS:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
print(f"\n[*] Waiting 12 seconds before next download...")
|
| 39 |
time.sleep(12)
|
| 40 |
|
| 41 |
try:
|
| 42 |
+
print(f"[*] Downloading from: {direct_download_link}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# Download the file from the direct link
|
| 45 |
+
filename = os.path.basename(urlparse(direct_download_link).path)
|
| 46 |
+
if not filename or "." not in filename: # Basic check for valid filename
|
| 47 |
+
filename = "downloaded_file" + str(int(time.time())) # Generate a unique name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
local_path = os.path.join(OUTPUT_DIR, filename)
|
| 50 |
+
print(f"[*] Downloading file to: {local_path}")
|
| 51 |
|
| 52 |
+
with requests.get(direct_download_link, stream=True) as r:
|
| 53 |
+
r.raise_for_status()
|
| 54 |
with open(local_path, "wb") as f:
|
| 55 |
for chunk in r.iter_content(chunk_size=8192):
|
| 56 |
f.write(chunk)
|
| 57 |
|
| 58 |
print(f"[✓] Downloaded: {filename}")
|
|
|
|
| 59 |
upload_to_dataset(local_path)
|
|
|
|
|
|
|
| 60 |
os.remove(local_path)
|
| 61 |
|
| 62 |
except Exception as e:
|
| 63 |
+
print(f"[!] Error with {direct_download_link}: {e}")
|
| 64 |
+
|
| 65 |
+
print("\n✅ All files processed.")
|
| 66 |
|
|
|