File size: 1,897 Bytes
61554bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import zipfile
import shutil
from pathlib import Path

def clean_filename(filename):
    # Split by '-' and keep only the part after it
    if '-' in filename:
        cleaned = filename.split('-')[1].strip()
        # Ensure it ends with .cube
        if cleaned.endswith('.cube'):
            return cleaned
    return filename

def extract_cube_files():
    # Create directories if they don't exist
    luts_dir = Path('luts')
    cube_luts_dir = Path('cube_luts')
    cube_luts_dir.mkdir(exist_ok=True)
    
    # Process each zip file in the luts directory
    for zip_path in luts_dir.glob('*.zip'):
        try:
            # Create a temporary directory for extraction
            temp_dir = Path('temp_extract')
            temp_dir.mkdir(exist_ok=True)
            
            # Extract the zip file
            with zipfile.ZipFile(zip_path, 'r') as zip_ref:
                zip_ref.extractall(temp_dir)
            
            # Find and move all .cube files
            for cube_file in temp_dir.rglob('*.cube'):
                # Clean up the filename
                new_name = clean_filename(cube_file.name)
                dest_path = cube_luts_dir / new_name
                
                # Handle duplicates
                counter = 1
                while dest_path.exists():
                    stem = Path(new_name).stem
                    suffix = Path(new_name).suffix
                    dest_path = cube_luts_dir / f"{stem}_{counter}{suffix}"
                    counter += 1
                
                # Move the file
                shutil.move(str(cube_file), str(dest_path))
            
            # Clean up temporary directory
            shutil.rmtree(temp_dir)
            
        except Exception as e:
            print(f"Error processing {zip_path}: {str(e)}")
            continue

if __name__ == "__main__":
    extract_cube_files()