Efreak
commited on
Commit
•
2d1ec2f
1
Parent(s):
06c4eb2
update script
Browse files- civitai.info.js +49 -13
civitai.info.js
CHANGED
@@ -1,10 +1,21 @@
|
|
1 |
-
/*
|
|
|
2 |
* unfortunately, civitai is storing some of them as LFS objects
|
3 |
* so the script outputs a list of errors along with scripts to fix them (delfiles.sh, replacefiles.sh)
|
4 |
* others files are blank, so just ignore the errors the second time, they're files that aren't on civitai
|
5 |
* now we get tot he important part: it parses all files, and dumps all of them into an array in civitai.info.json for further processing
|
6 |
* Run once, run delfiles.bat or delfiles.sh to get rid of the bad ones, then run replacefiles.sh to fetch them from civitai.
|
|
|
|
|
|
|
|
|
7 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
var path = require('path'),
|
9 |
fs = require('fs');
|
10 |
|
@@ -30,26 +41,51 @@ function fromDir(startPath, filter, arr) {
|
|
30 |
return arr;
|
31 |
};
|
32 |
|
33 |
-
var addons=[];
|
34 |
-
var errors=[];
|
35 |
var push=function(file){
|
36 |
try{
|
37 |
var addon=JSON.parse(fs.readFileSync(file));
|
38 |
-
addon.mirror_path=file; // Add the location we found the file.
|
39 |
-
addons.push(addon)
|
40 |
} catch(err) {
|
41 |
-
console.
|
42 |
-
console.error(err)
|
43 |
errors.push(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
};
|
46 |
|
47 |
var files=fromDir('.', '.civitai.info');
|
48 |
-
files.
|
49 |
-
|
|
|
50 |
fs.writeFileSync('civitai.info.json',JSON.stringify(addons))
|
51 |
-
fs.writeFileSync('errors.json',JSON.stringify(
|
52 |
//console.error("Error with the following files:",errors);
|
53 |
-
fs.writeFileSync('delfiles.bat','@echo off\n\n'+
|
54 |
-
fs.writeFileSync('delfiles.sh',
|
55 |
-
fs.writeFileSync('replacefiles.sh',errors.map(e=>{return "wget \"https://huggingface.co/anonderpling/civitai_mirror/resolve/main/"+(e.split(" ").join("%23")+"\" -O \""+e+"\"")}).join('\n').split('\\').join('\/'))
|
|
|
1 |
+
/*
|
2 |
+
* This script exists to merge all .info files into one array.
|
3 |
* unfortunately, civitai is storing some of them as LFS objects
|
4 |
* so the script outputs a list of errors along with scripts to fix them (delfiles.sh, replacefiles.sh)
|
5 |
* others files are blank, so just ignore the errors the second time, they're files that aren't on civitai
|
6 |
* now we get tot he important part: it parses all files, and dumps all of them into an array in civitai.info.json for further processing
|
7 |
* Run once, run delfiles.bat or delfiles.sh to get rid of the bad ones, then run replacefiles.sh to fetch them from civitai.
|
8 |
+
*
|
9 |
+
* the reason I chose to output scripts (and use two of them) rather than doing it internally is two-fold:
|
10 |
+
* 1. I can inspect delfiles.sh being deleted before running it
|
11 |
+
* 2. I can rewrite the replacefiles.sh with a script to use a download manager (aria2c) when it's large. (this script is intended to be used in colab)
|
12 |
*/
|
13 |
+
|
14 |
+
// change this to true if you want the full contents of every .info file, otherwise we're deleting a bunch of stuff I don't care about
|
15 |
+
// keep in mind this changes the format of the file (I've replaced the image object with an array of urls that have no metadata)
|
16 |
+
// so any scripts I write won't work with it anymore. This reduced the size of the file by nearly 80%...The original data is still in the original files.
|
17 |
+
var fullFiles = false;
|
18 |
+
|
19 |
var path = require('path'),
|
20 |
fs = require('fs');
|
21 |
|
|
|
41 |
return arr;
|
42 |
};
|
43 |
|
44 |
+
var addons=[]; var errors=[]; errors2=[];
|
|
|
45 |
var push=function(file){
|
46 |
try{
|
47 |
var addon=JSON.parse(fs.readFileSync(file));
|
|
|
|
|
48 |
} catch(err) {
|
49 |
+
console.error(file + " is probably an LFS pointer. Will be added to delfiles and replacefiles scripts!");
|
|
|
50 |
errors.push(file);
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
if(Object.keys(addon).length==0) {
|
54 |
+
console.error(file + " is an empty file! Will be added to delfiles script! Assuming it's not a mistake, it will *not* be replaced!");
|
55 |
+
errors2.push(file);
|
56 |
+
return;
|
57 |
}
|
58 |
+
addon.mirror_path=file; // Add the location we found the file.
|
59 |
+
|
60 |
+
// We're going to clean information idc about. Change `false` to `true` at the top if you want all data.
|
61 |
+
if(fullFiles == true) {
|
62 |
+
addons.push(addon);
|
63 |
+
return;
|
64 |
+
}
|
65 |
+
delete addon.model.poi;
|
66 |
+
'createdAt,updatedAt,earlyAccessTimeFrame,downloadUrl,description'.split(',').forEach(key=>{delete addon[key]});
|
67 |
+
for(file=addon.files.length-1;file>=0;file--) {
|
68 |
+
if(addon.files[file].type == 'Training Data' || addon.files[file].type == 'Config') {
|
69 |
+
addon.files.splice(file,1);
|
70 |
+
} else {
|
71 |
+
'sizeKB,format,pickleScanResult,pickleScanMessage,virusScanResult,scannedAt,hashes,primary,downloadUrl'.split(',').forEach(key=>{
|
72 |
+
delete addon.files[file][key];
|
73 |
+
});
|
74 |
+
}
|
75 |
+
};
|
76 |
+
var imgs=addon.images;
|
77 |
+
addon.images=[];
|
78 |
+
imgs.forEach(img=>{addon.images.push(img.url.replace('https://imagecache.civitai.com/',''))});
|
79 |
+
addons.push(addon);
|
80 |
};
|
81 |
|
82 |
var files=fromDir('.', '.civitai.info');
|
83 |
+
files.forEach(file=>{push(file)});
|
84 |
+
//push(files[0]);
|
85 |
+
var errs=[...errors,...errors2].sort();
|
86 |
fs.writeFileSync('civitai.info.json',JSON.stringify(addons))
|
87 |
+
fs.writeFileSync('errors.json',JSON.stringify(errs))
|
88 |
//console.error("Error with the following files:",errors);
|
89 |
+
fs.writeFileSync('delfiles.bat','@echo off\n\n'+errs.map(e=>{return "del \""+ e + "\""}).join('\n'))
|
90 |
+
fs.writeFileSync('delfiles.sh',errs.map(e=>{return "rm \""+ e + "\""}).join('\n').split('\\').join('/'))
|
91 |
+
fs.writeFileSync('replacefiles.sh',errors.map(e=>{return "wget \"https://huggingface.co/anonderpling/civitai_mirror/resolve/main/"+(e.split(" ").join("%23")+"\" -O \""+e+"\"")}).join('\n').split('\\').join('\/'))
|