Add dart implementation and download in all res

This commit is contained in:
syaifakmal 2024-09-26 10:27:46 +07:00
parent 82e50c64f0
commit 18d29b68ad
4 changed files with 107 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.DS_Store .DS_Store
downloads downloads
.dart_tool
pubspec.lock

View File

@ -1,12 +1,12 @@
``` ```
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
| $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$ | $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$
| $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$ | $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$
| $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$ | $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$
| $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$ | $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$
| $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$ | $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$
| $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/ | $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/
|__/ |__/|__/ \__/|_______/ \______/ |_______/ |__/ |__/|__/ \__/|_______/ \______/ |_______/
``` ```
_Because selling out is bad_ _Because selling out is bad_
@ -30,6 +30,13 @@ MKBSD comes in two variants! Node.js and Python.
4. Wait a little. 4. Wait a little.
5. All wallpapers are now in a newly created `downloads` subfolder. 5. All wallpapers are now in a newly created `downloads` subfolder.
### Running in Dart
1. Ensure you have Node.js installed.
2. Run `dart run mkbsd.dart`
3. Wait a little.
4. All wallpapers are now in a newly created `downloads` subfolder.
## FAQ ## FAQ
### Q: What's the story behind this? ### Q: What's the story behind this?

81
mkbsd.dart Normal file
View File

@ -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
pubspec.yaml Normal file
View File

@ -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