23 lines
No EOL
883 B
C#
23 lines
No EOL
883 B
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace RC2BotArchiver;
|
|
|
|
public static class DownloadImages
|
|
{
|
|
public static async Task DoIt(HttpClient client)
|
|
{
|
|
foreach (var dir in Directory.EnumerateDirectories("robots"))
|
|
{
|
|
var json = await File.ReadAllTextAsync(Path.Combine(dir, "metadata.json"));
|
|
var doc = JsonDocument.Parse(json);
|
|
var url = doc.RootElement.GetProperty("image").GetString();
|
|
if (url is null) continue;
|
|
var response = await client.GetAsync(url);
|
|
await using var stream = await response.Content.ReadAsStreamAsync();
|
|
await using var fs = File.OpenWrite(Path.Combine(dir, "thumbnail.jpeg"));
|
|
await stream.CopyToAsync(fs);
|
|
Console.WriteLine($"Saved image for {doc.RootElement.GetProperty("name")}");
|
|
}
|
|
}
|
|
} |