File size: 1,822 Bytes
74118c5
0391459
 
 
74118c5
0391459
74118c5
0391459
 
 
b9eb189
bcd4b41
0391459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import shutil
from huggingface_hub import hf_hub_download, HfApi
import subprocess

# Config
HF_TOKEN = os.environ.get("HF_TOKEN")
SOURCE_REPO = "Fred808/BG1"
DEST_REPO = "Fred808/BG2"
RAR_DIR = "ZBrush/"
EXCLUDED = ["ZBrush/3DConceptArtist_TheUltimateZbrushGuide_DownloadPirate.com.rar"]
os.environ["HF_HUB_CACHE"] = "/tmp/hf_cache"

# Setup API client
api = HfApi(token=HF_TOKEN)

# Step 1: Get all files from the source repo
from huggingface_hub import list_repo_files
all_files = list_repo_files(repo_id=SOURCE_REPO, repo_type="dataset", token=HF_TOKEN)
zbrush_rars = [f for f in all_files if f.startswith(RAR_DIR) and f.endswith(".rar") and f not in EXCLUDED]

# Process each file one by one
for rar_file in zbrush_rars:
    print(f"\n🔽 Downloading: {rar_file}")
    local_rar_path = hf_hub_download(
        repo_id=SOURCE_REPO,
        filename=rar_file,
        repo_type="dataset",
        token=HF_TOKEN
    )

    # Create clean output dir
    extract_dir = "extracted_tmp"
    os.makedirs(extract_dir, exist_ok=True)

    print(f"📦 Extracting {rar_file}...")
    subprocess.run(["unrar", "x", "-o+", local_rar_path, extract_dir])

    # Upload extracted files one by one
    for root, _, files in os.walk(extract_dir):
        for fname in files:
            full_path = os.path.join(root, fname)
            relative_path = os.path.relpath(full_path, extract_dir)
            print(f"⬆️ Uploading: {relative_path}")
            api.upload_file(
                path_or_fileobj=full_path,
                path_in_repo=relative_path,
                repo_id=DEST_REPO,
                repo_type="dataset"
            )

    # Clean up everything
    print(f"🧹 Cleaning up...")
    shutil.rmtree(extract_dir)
    os.remove(local_rar_path)

print("\n✅ All files processed and uploaded.")