Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dart implementation and download in all res #40

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
downloads
.dart_tool
pubspec.lock
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
| $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$
| $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$
| $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$
| $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$
| $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$
| $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/
|__/ |__/|__/ \__/|_______/ \______/ |_______/
|__/ |__/|__/ \__/|_______/ \______/ |_______/
```

_Because selling out is bad_
Expand All @@ -30,6 +30,13 @@ 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 Dart

1. Ensure you have Dart installed.
2. Run `dart run mkbsd.dart`
3. Wait a little.
4. All wallpapers are now in a newly created `downloads` subfolder.

## FAQ

### Q: What's the story behind this?
Expand Down
81 changes: 81 additions & 0 deletions mkbsd.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path;

void main(List<String> arguments) async {
ascii_art();

sleep(Duration(seconds: 5));

try {
final String url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s';
final response = await http.get(Uri.parse(url));

if (response.statusCode != 200) {
throw Exception("Failed to fetch JSON file: ${response.reasonPhrase}");
}

if (!response.body.contains("data")) {
throw Exception('⛔ JSON does not have a "data" property at its root.');
}

final Map<String, dynamic> data = jsonDecode(response.body)["data"];

final downloadDir = Directory("downloads");

if (!downloadDir.existsSync()) {
downloadDir.createSync(recursive: true);
print("📁 Created directory: ${downloadDir}`");
}

for (String key in data.keys) {
final subDir = Directory("${downloadDir.path}/$key");
if (!subDir.existsSync()) {
subDir.createSync(recursive: true);
}

Map<String, dynamic> subproperty = data[key];

for (String subKey in subproperty.keys) {
final String imageURL = subproperty[subKey];
final uri = Uri.parse(imageURL);

final String ext = path.extension(uri.path).isNotEmpty ? path.extension(uri.path) : '.jpg';
final String filename = "${subKey}${ext}";
final String filePath = path.join(subDir.path, filename);
await downloadImage(uri, filePath);
print("🖼️ Saved image to ${filePath}");
sleep(Duration(milliseconds: 250));
}
}
} catch (e) {
print("Error: $e");
}
}

Future<void> downloadImage(Uri uri, String savePath) async {
final response = await http.get(uri);

if (response.statusCode != 200) {
throw Exception("Failed to download image: ${response.reasonPhrase}");
}

final file = File(savePath);

await file.writeAsBytes(response.bodyBytes);
}

void ascii_art() {
print("""
/\$\$ /\$\$ /\$\$ /\$\$ /\$\$\$\$\$\$\$ /\$\$\$\$\$\$ /\$\$\$\$\$\$\$
| \$\$\$ /\$\$\$| \$\$ /\$\$/| \$\$__ \$\$ /\$\$__ \$\$| \$\$__ \$\$
| \$\$\$\$ /\$\$\$\$| \$\$ /\$\$/ | \$\$ \\ \$\$| \$\$ \\__/| \$\$ \\ \$\$
| \$\$ \$\$/\$\$ \$\$| \$\$\$\$\$/ | \$\$\$\$\$\$\$ | \$\$\$\$\$\$ | \$\$ | \$\$
| \$\$ \$\$\$| \$\$| \$\$ \$\$ | \$\$__ \$\$ \\____ \$\$| \$\$ | \$\$
| \$\$\\ \$ | \$\$| \$\$\\ \$\$ | \$\$ \\ \$\$ /\$\$ \\ \$\$| \$\$ | \$\$
| \$\$ \\/ | \$\$| \$\$ \\ \$\$| \$\$\$\$\$\$\$/| \$\$\$\$\$\$/| \$\$\$\$\$\$\$/
|__/ |__/|__/ \\__/|_______/ \\______/ |_______/""");
print("");
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...");
}
15 changes: 15 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: mkbsd
description: A sample command-line application.
version: 1.0.0

environment:
sdk: ^3.0.6

# Add regular dependencies here.
dependencies:
http: ^1.1.0
path: ^1.9.0

dev_dependencies:
lints: ^2.0.0
test: ^1.21.0