This commit is contained in:
dinnerhe 2024-09-30 23:37:13 -04:00 committed by GitHub
commit 7b31233999
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 145 additions and 1 deletions

View file

@ -11,9 +11,11 @@
_Because selling out is bad_
Based on nadimkobeissi's [MKBSD](https://github.com/nadimkobeissi/mkbsd)
## How to use
MKBSD comes in two variants! Node.js and Python.
MKBSD comes in three variants! Node.js, Python and C#.
### Running in Node.js
@ -30,6 +32,15 @@ MKBSD comes in two variants! Node.js and Python.
4. Wait a little.
5. All wallpapers are now in a newly created `downloads` subfolder.
### Running in C#
1. Ensure you have dotnet installed.
2. Navigate to `mkbsdSharp` folder.
3. Run `dotnet run`
4. Wait a little.
4. All wallpapers are now in a newly created `downloads` subfolder.
## FAQ
### Q: What's the story behind this?

3
mkbsdSharp/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.idea/
bin/
obj/

104
mkbsdSharp/Program.cs Normal file
View file

@ -0,0 +1,104 @@
// Licensed under the WTFPL License
using System.Text.Json;
class Program
{
private static readonly HttpClient Client = new();
static async Task Main(string[] args)
{
AsciiArt();
await Task.Delay(1000);
string url = "https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s";
try
{
HttpResponseMessage response = await Client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"⛔ Failed to fetch JSON file: {response.ReasonPhrase}");
}
DataType? jsonData =
await JsonSerializer.DeserializeAsync<DataType>(await response.Content.ReadAsStreamAsync());
var data = jsonData?.data;
if (data == null)
{
throw new Exception("⛔ JSON does not have a 'data' property at its root.");
}
string downloadDir = Path.Combine(Directory.GetCurrentDirectory(), "downloads");
if (!Directory.Exists(downloadDir))
{
Directory.CreateDirectory(downloadDir);
Console.WriteLine($"📁 Created directory: {downloadDir}");
}
var keyvaluepair = data.Values.ToList();
for(int i=0; i< keyvaluepair.Count; i++ )
{
var subproperty = keyvaluepair[i];
if (subproperty.TryGetValue("dhd", out var imageUrl))
{
Console.WriteLine("🔍 Found image URL!");
string ext = Path.GetExtension(new Uri(imageUrl).AbsolutePath) ?? ".jpg";
string filename = $"{i}{ext}";
string filePath = Path.Combine(downloadDir, filename);
await DownloadImage(imageUrl, filePath);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
static async Task DownloadImage(string url, string filePath)
{
await Task.Delay(100);
HttpResponseMessage response = await Client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Failed to download image: {response.ReasonPhrase}");
}
byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync(filePath, imageBytes);
Console.WriteLine($"🖼️ Saved image to {filePath}");
await Task.Delay(250);
}
static void AsciiArt()
{
Console.WriteLine(@"
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
| $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$
| $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$
| $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$
| $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$
| $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$
| $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/
|__/ |__/|__/ \__/|_______/ \______/ |_______/");
Console.WriteLine();
Console.WriteLine("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...");
}
private class DataType
{
public int version { get; set; }
public Dictionary<string, Dictionary<string, string>>? data { get; set; }
}
}

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

16
mkbsdSharp/mkbsdSharp.sln Normal file
View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mkbsdSharp", "mkbsdSharp.csproj", "{F6B460ED-5903-4500-8C1E-93EAD8971B12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F6B460ED-5903-4500-8C1E-93EAD8971B12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6B460ED-5903-4500-8C1E-93EAD8971B12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6B460ED-5903-4500-8C1E-93EAD8971B12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6B460ED-5903-4500-8C1E-93EAD8971B12}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal