Last active
January 20, 2024 13:52
-
-
Save SteveGilham/14147b52ccb9090fdd0ce0be11cd9953 to your computer and use it in GitHub Desktop.
Extract the prompt metadata from a SD-WebUI .png file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
let dumpParams f = | |
let bytes = File.ReadAllBytes f | |
// printfn "%A bytes" bytes.Length | |
let rec readchunk index = | |
// printfn "readchunk %A" index | |
if index < bytes.Length then | |
let field = [| bytes[index+3]; bytes[index+2]; bytes[index+1]; bytes[index] |] | |
let length = BitConverter.ToInt32(field, 0) | |
let chunk = System.Text.Encoding.UTF8.GetString(bytes, index+4, 4) | |
//printfn "%A %A" chunk length | |
if chunk.Equals("tEXt") || chunk.Equals("iTXt") | |
then | |
let body = System.Text.Encoding.UTF8.GetString(bytes, index+19, length - 11) | |
printfn "%s" body | |
else | |
readchunk (index + 12 + length) | |
readchunk 8 | |
let dump ((d:DateOnly), l) = | |
l | |
|> Seq.iter (fun (f:string) -> let fn = Path.GetFileName f | |
printfn " %A on %A" (fn.Substring(0,5)) (d.ToString("yyyy-MM-dd")) | |
dumpParams f) | |
let scandir dir = | |
printfn "%s" dir | |
let files = Directory.GetFiles(dir, "?????-*.png") | |
files | |
|> Seq.groupBy (fun f -> (File.GetLastWriteTime f) |> DateOnly.FromDateTime) | |
|> Seq.sortBy (fun (d,l) -> d) | |
|> Seq.map (fun (d,l) -> (d, l |> Seq.sort)) | |
|> Seq.iter dump | |
let targets = Directory.GetDirectories(".", "*", SearchOption.AllDirectories ) | |
targets | |
|> Seq.sort | |
|> Seq.iter scandir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment