Delete download_world.py
Browse files- download_world.py +0 -129
download_world.py
DELETED
|
@@ -1,129 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
|
| 3 |
-
import os
|
| 4 |
-
import shutil
|
| 5 |
-
import zipfile
|
| 6 |
-
import sys
|
| 7 |
-
import gdown
|
| 8 |
-
|
| 9 |
-
# Get environment variable for Google Drive folder URL
|
| 10 |
-
FOLDER_URL = os.getenv("FOLDER_URL")
|
| 11 |
-
|
| 12 |
-
# Directories for downloading and extracting
|
| 13 |
-
DOWNLOAD_DIR = "/tmp/gdrive_download"
|
| 14 |
-
EXTRACT_DIR = "/tmp/extracted_world"
|
| 15 |
-
APP_DIR = "/app"
|
| 16 |
-
|
| 17 |
-
def download_and_extract():
|
| 18 |
-
"""Download world files from Google Drive and extract them"""
|
| 19 |
-
|
| 20 |
-
print(">>> Starting world download from Google Drive...")
|
| 21 |
-
|
| 22 |
-
# Check if FOLDER_URL is set
|
| 23 |
-
if not FOLDER_URL:
|
| 24 |
-
print("⚠️ FOLDER_URL environment variable not set. Skipping download.")
|
| 25 |
-
print(">>> Minecraft will create a default world.")
|
| 26 |
-
return False
|
| 27 |
-
|
| 28 |
-
try:
|
| 29 |
-
# Clean up and create directories
|
| 30 |
-
shutil.rmtree(DOWNLOAD_DIR, ignore_errors=True)
|
| 31 |
-
shutil.rmtree(EXTRACT_DIR, ignore_errors=True)
|
| 32 |
-
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
| 33 |
-
os.makedirs(EXTRACT_DIR, exist_ok=True)
|
| 34 |
-
|
| 35 |
-
print(f">>> Downloading from: {FOLDER_URL}")
|
| 36 |
-
|
| 37 |
-
# Download from Google Drive
|
| 38 |
-
try:
|
| 39 |
-
gdown.download_folder(
|
| 40 |
-
url=FOLDER_URL,
|
| 41 |
-
output=DOWNLOAD_DIR,
|
| 42 |
-
use_cookies=False,
|
| 43 |
-
quiet=False,
|
| 44 |
-
remaining_ok=True
|
| 45 |
-
)
|
| 46 |
-
print("✅ Downloaded from Google Drive")
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"❌ Failed to download folder: {e}")
|
| 49 |
-
print(">>> Make sure the folder is public (Anyone with link)")
|
| 50 |
-
print(">>> Minecraft will create a default world.")
|
| 51 |
-
return False
|
| 52 |
-
|
| 53 |
-
# Check if any files were downloaded
|
| 54 |
-
if not os.listdir(DOWNLOAD_DIR):
|
| 55 |
-
print("⚠️ No files found in Google Drive folder")
|
| 56 |
-
print(">>> Minecraft will create a default world.")
|
| 57 |
-
return False
|
| 58 |
-
|
| 59 |
-
# Extract all zip files
|
| 60 |
-
zip_found = False
|
| 61 |
-
for root, _, files in os.walk(DOWNLOAD_DIR):
|
| 62 |
-
for f in files:
|
| 63 |
-
if f.endswith(".zip"):
|
| 64 |
-
zip_found = True
|
| 65 |
-
zip_path = os.path.join(root, f)
|
| 66 |
-
print(f">>> Extracting: {f}")
|
| 67 |
-
with zipfile.ZipFile(zip_path, 'r') as z:
|
| 68 |
-
z.extractall(EXTRACT_DIR)
|
| 69 |
-
print(f"✅ Extracted: {f}")
|
| 70 |
-
|
| 71 |
-
if not zip_found:
|
| 72 |
-
print("⚠️ No zip files found in download")
|
| 73 |
-
# Try to copy non-zip files directly
|
| 74 |
-
for item in os.listdir(DOWNLOAD_DIR):
|
| 75 |
-
src = os.path.join(DOWNLOAD_DIR, item)
|
| 76 |
-
dst = os.path.join(EXTRACT_DIR, item)
|
| 77 |
-
if os.path.isdir(src):
|
| 78 |
-
shutil.copytree(src, dst)
|
| 79 |
-
else:
|
| 80 |
-
shutil.copy2(src, dst)
|
| 81 |
-
|
| 82 |
-
# Fix common typo in world_nether folder name
|
| 83 |
-
bad_nether = os.path.join(EXTRACT_DIR, "world_nither")
|
| 84 |
-
good_nether = os.path.join(EXTRACT_DIR, "world_nether")
|
| 85 |
-
if os.path.exists(bad_nether) and not os.path.exists(good_nether):
|
| 86 |
-
os.rename(bad_nether, good_nether)
|
| 87 |
-
print("✅ Fixed world_nether folder name typo")
|
| 88 |
-
|
| 89 |
-
# Copy world folders to app directory
|
| 90 |
-
world_folders = {
|
| 91 |
-
"world": os.path.join(EXTRACT_DIR, "world"),
|
| 92 |
-
"world_nether": os.path.join(EXTRACT_DIR, "world_nether"),
|
| 93 |
-
"world_the_end": os.path.join(EXTRACT_DIR, "world_the_end"),
|
| 94 |
-
"plugins": os.path.join(EXTRACT_DIR, "plugins")
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
copied_any = False
|
| 98 |
-
for name, src_path in world_folders.items():
|
| 99 |
-
if os.path.exists(src_path):
|
| 100 |
-
dst_path = os.path.join(APP_DIR, name)
|
| 101 |
-
# Remove existing folder if it exists
|
| 102 |
-
if os.path.exists(dst_path):
|
| 103 |
-
shutil.rmtree(dst_path)
|
| 104 |
-
shutil.copytree(src_path, dst_path)
|
| 105 |
-
print(f"✅ Copied {name} to /app/")
|
| 106 |
-
copied_any = True
|
| 107 |
-
else:
|
| 108 |
-
print(f"⚠️ {name} not found in extracted files")
|
| 109 |
-
|
| 110 |
-
# Clean up temporary directories
|
| 111 |
-
shutil.rmtree(DOWNLOAD_DIR, ignore_errors=True)
|
| 112 |
-
shutil.rmtree(EXTRACT_DIR, ignore_errors=True)
|
| 113 |
-
|
| 114 |
-
if copied_any:
|
| 115 |
-
print("✅ World data setup complete!")
|
| 116 |
-
return True
|
| 117 |
-
else:
|
| 118 |
-
print("⚠️ No world folders found in extracted files")
|
| 119 |
-
print(">>> Minecraft will create a default world.")
|
| 120 |
-
return False
|
| 121 |
-
|
| 122 |
-
except Exception as e:
|
| 123 |
-
print(f"❌ Error during download/extraction: {e}")
|
| 124 |
-
print(">>> Minecraft will create a default world.")
|
| 125 |
-
return False
|
| 126 |
-
|
| 127 |
-
if __name__ == "__main__":
|
| 128 |
-
success = download_and_extract()
|
| 129 |
-
sys.exit(0 if success else 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|