diff --git a/.gitignore b/.gitignore index de2b2c6..fc50f08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store downloads +.dart_tool +pubspec.lock \ No newline at end of file diff --git a/README.md b/README.md index 2d34182..e537731 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ ``` - /$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$ + /$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$ | $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$ | $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$ | $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$ | $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$ | $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$ | $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/ -|__/ |__/|__/ \__/|_______/ \______/ |_______/ +|__/ |__/|__/ \__/|_______/ \______/ |_______/ ``` _Because selling out is bad_ @@ -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 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 ### Q: What's the story behind this? diff --git a/mkbsd.dart b/mkbsd.dart new file mode 100644 index 0000000..c3a48b1 --- /dev/null +++ b/mkbsd.dart @@ -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 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 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 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 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..."); +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..5ab3f0f --- /dev/null +++ b/pubspec.yaml @@ -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