forked from slahiri/ComfyUI-Workflow-Models-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_metadata.py
More file actions
266 lines (210 loc) · 7.95 KB
/
Copy pathupdate_metadata.py
File metadata and controls
266 lines (210 loc) · 7.95 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env python3
"""
Update Metadata Script
Downloads the latest metadata files from ComfyUI Manager GitHub repository.
Usage:
python update_metadata.py # Update all metadata files
python update_metadata.py --check # Check for updates without downloading
"""
import os
import sys
import json
import hashlib
import urllib.request
import urllib.error
from pathlib import Path
from datetime import datetime
# Metadata files to download from ComfyUI Manager
METADATA_FILES = {
'extension-node-map.json': {
'url': 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json',
'description': 'Node to GitHub URL mappings'
},
'model-list.json': {
'url': 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json',
'description': 'Model filename to type/directory mappings'
},
'custom-node-list.json': {
'url': 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json',
'description': 'Custom node reference information'
}
}
def get_metadata_dir():
"""Get the metadata directory path"""
return Path(__file__).parent / 'metadata'
def get_file_hash(filepath):
"""Calculate MD5 hash of a file"""
if not filepath.exists():
return None
hash_md5 = hashlib.md5()
with open(filepath, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def get_content_hash(content):
"""Calculate MD5 hash of content bytes"""
return hashlib.md5(content).hexdigest()
def download_file(url, timeout=30):
"""Download file content from URL"""
try:
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (ComfyUI-Workflow-Models-Identifier)')
with urllib.request.urlopen(req, timeout=timeout) as response:
return response.read()
except urllib.error.HTTPError as e:
print(f" HTTP Error {e.code}: {e.reason}")
return None
except urllib.error.URLError as e:
print(f" URL Error: {e.reason}")
return None
except Exception as e:
print(f" Error: {str(e)}")
return None
def format_size(size_bytes):
"""Format bytes to human readable size"""
if size_bytes < 1024:
return f"{size_bytes} B"
elif size_bytes < 1024 * 1024:
return f"{size_bytes / 1024:.1f} KB"
else:
return f"{size_bytes / (1024 * 1024):.2f} MB"
def update_metadata(check_only=False):
"""Update all metadata files from remote sources"""
metadata_dir = get_metadata_dir()
metadata_dir.mkdir(exist_ok=True)
print("=" * 60)
print("COMFYUI METADATA UPDATER")
print("=" * 60)
print(f"Source: ComfyUI-Manager GitHub Repository")
print(f"Target: {metadata_dir}")
print(f"Mode: {'Check only' if check_only else 'Update'}")
print("=" * 60)
print()
results = {
'updated': [],
'unchanged': [],
'errors': [],
'new': []
}
for filename, info in METADATA_FILES.items():
print(f"[{filename}]")
print(f" Description: {info['description']}")
local_path = metadata_dir / filename
local_hash = get_file_hash(local_path)
local_exists = local_path.exists()
if local_exists:
local_size = local_path.stat().st_size
local_mtime = datetime.fromtimestamp(local_path.stat().st_mtime)
print(f" Local: {format_size(local_size)}, modified {local_mtime.strftime('%Y-%m-%d %H:%M')}")
else:
print(f" Local: Not found")
print(f" Downloading from: {info['url'][:60]}...")
content = download_file(info['url'])
if content is None:
print(f" Status: FAILED to download")
results['errors'].append(filename)
print()
continue
remote_hash = get_content_hash(content)
remote_size = len(content)
print(f" Remote: {format_size(remote_size)}")
if local_hash == remote_hash:
print(f" Status: UNCHANGED (hashes match)")
results['unchanged'].append(filename)
elif not local_exists:
if not check_only:
with open(local_path, 'wb') as f:
f.write(content)
print(f" Status: NEW file downloaded")
else:
print(f" Status: NEW file available")
results['new'].append(filename)
else:
if not check_only:
with open(local_path, 'wb') as f:
f.write(content)
print(f" Status: UPDATED")
else:
print(f" Status: UPDATE available")
results['updated'].append(filename)
print()
# Summary
print("=" * 60)
print("SUMMARY")
print("=" * 60)
if results['new']:
print(f"New: {len(results['new'])} file(s)")
for f in results['new']:
print(f" - {f}")
if results['updated']:
print(f"Updated: {len(results['updated'])} file(s)")
for f in results['updated']:
print(f" - {f}")
if results['unchanged']:
print(f"Unchanged: {len(results['unchanged'])} file(s)")
if results['errors']:
print(f"Errors: {len(results['errors'])} file(s)")
for f in results['errors']:
print(f" - {f}")
print("=" * 60)
if check_only and (results['new'] or results['updated']):
print("\nRun without --check to download updates.")
return len(results['errors']) == 0
def show_metadata_stats():
"""Show statistics about current metadata files"""
metadata_dir = get_metadata_dir()
print("=" * 60)
print("CURRENT METADATA FILES")
print("=" * 60)
if not metadata_dir.exists():
print("Metadata directory not found. Run update first.")
return
for filename, info in METADATA_FILES.items():
local_path = metadata_dir / filename
print(f"\n[{filename}]")
print(f" Description: {info['description']}")
if local_path.exists():
size = local_path.stat().st_size
mtime = datetime.fromtimestamp(local_path.stat().st_mtime)
# Try to get entry count
try:
with open(local_path, 'r', encoding='utf-8') as f:
data = json.load(f)
if filename == 'extension-node-map.json':
# Count total nodes across all extensions
total_nodes = sum(
len(v[0]) if isinstance(v, list) and len(v) > 0 and isinstance(v[0], list) else 0
for v in data.values()
)
print(f" Extensions: {len(data)}")
print(f" Total nodes: {total_nodes}")
elif filename == 'model-list.json':
models = data.get('models', [])
print(f" Models: {len(models)}")
elif filename == 'custom-node-list.json':
nodes = data.get('custom_nodes', [])
print(f" Custom nodes: {len(nodes)}")
except:
pass
print(f" Size: {format_size(size)}")
print(f" Modified: {mtime.strftime('%Y-%m-%d %H:%M:%S')}")
else:
print(f" Status: NOT FOUND")
print()
def main():
check_only = '--check' in sys.argv
stats_only = '--stats' in sys.argv
if '--help' in sys.argv or '-h' in sys.argv:
print(__doc__)
print("\nOptions:")
print(" --check Check for updates without downloading")
print(" --stats Show statistics about current metadata files")
print(" --help Show this help message")
return
if stats_only:
show_metadata_stats()
return
success = update_metadata(check_only=check_only)
sys.exit(0 if success else 1)
if __name__ == '__main__':
main()