Skip to content

Commit

Permalink
skip hyrdus check and only check rating:safe on donmai
Browse files Browse the repository at this point in the history
  • Loading branch information
NO-ob committed Feb 19, 2023
1 parent b159934 commit c25219d
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 409 deletions.
34 changes: 34 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "loliSnatcher",
"request": "launch",
"type": "dart"
},
{
"name": "loliSnatcher (play store)",
"request": "launch",
"type": "dart",
"flutterMode": "profile",
"args": [
"--dart-define=LS_IS_STORE=true"
]
},
{
"name": "loliSnatcher (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "loliSnatcher (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ linter:
prefer_is_empty: true
non_constant_identifier_names: true
overridden_fields: true
avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
file_names: true # .dart files should use 'lowercase_with_underscores' naming scheme
always_use_package_imports: true
unawaited_futures: true
use_build_context_synchronously: false
require_trailing_commas: true

# analyzer:
# language:
Expand Down
42 changes: 29 additions & 13 deletions lib/src/boorus/danbooru_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DanbooruHandler extends BooruHandler {

@override
String validateTags(String tags) {
if (tags.toLowerCase().contains('rating:safe')) {
if (tags.toLowerCase().contains('rating:safe') &&
booru.baseURL!.contains('danbooru.donmai.us')) {
tags = tags.toLowerCase().replaceAll('rating:safe', 'rating:general');
}
return tags;
Expand Down Expand Up @@ -57,16 +58,25 @@ class DanbooruHandler extends BooruHandler {
*/
if (current.containsKey("file_url")) {
if ((current["file_url"].length > 0)) {
addTagsWithType(current['tag_string_general'].toString().split(" "), TagType.none);
addTagsWithType(current['tag_string_character'].toString().split(" "), TagType.character);
addTagsWithType(current['tag_string_copyright'].toString().split(" "), TagType.copyright);
addTagsWithType(current['tag_string_artist'].toString().split(" "), TagType.artist);
addTagsWithType(current['tag_string_meta'].toString().split(" "), TagType.meta);
addTagsWithType(
current['tag_string_general'].toString().split(" "), TagType.none);
addTagsWithType(current['tag_string_character'].toString().split(" "),
TagType.character);
addTagsWithType(current['tag_string_copyright'].toString().split(" "),
TagType.copyright);
addTagsWithType(
current['tag_string_artist'].toString().split(" "), TagType.artist);
addTagsWithType(
current['tag_string_meta'].toString().split(" "), TagType.meta);

final bool isZip = current['file_url'].toString().endsWith(".zip");
final String? dateStr = current['created_at']?.toString().substring(0, current['created_at']!.toString().length - 6);
final String? dateStr = current['created_at']
?.toString()
.substring(0, current['created_at']!.toString().length - 6);
BooruItem item = BooruItem(
fileURL: isZip ? current["large_file_url"].toString() : current["file_url"].toString(),
fileURL: isZip
? current["large_file_url"].toString()
: current["file_url"].toString(),
sampleURL: current["large_file_url"].toString(),
thumbnailURL: current["preview_file_url"].toString(),
tagsList: current["tag_string"].toString().split(" "),
Expand All @@ -82,7 +92,8 @@ class DanbooruHandler extends BooruHandler {
sources: [current["source"].toString()],
md5String: current["md5"].toString(),
postDate: dateStr, // 2021-06-17T16:27:45.743-04:00
postDateFormat: "yyyy-MM-dd't'HH:mm:ss'.'SSSZ", // when timezone support added: "yyyy-MM-dd't'HH:mm:ssZ",
postDateFormat:
"yyyy-MM-dd't'HH:mm:ss'.'SSSZ", // when timezone support added: "yyyy-MM-dd't'HH:mm:ssZ",
);
return item;
} else {
Expand All @@ -101,8 +112,10 @@ class DanbooruHandler extends BooruHandler {
@override
String makeURL(String tags) {
// EXAMPLE: https://danbooru.donmai.us/posts.json?tags=rating:safe%20order:rank&limit=20&page=1
final String loginStr = booru.userID?.isNotEmpty == true ? "&login=${booru.userID}" : "";
final String apiKeyStr = booru.apiKey?.isNotEmpty == true ? "&api_key=${booru.apiKey}" : "";
final String loginStr =
booru.userID?.isNotEmpty == true ? "&login=${booru.userID}" : "";
final String apiKeyStr =
booru.apiKey?.isNotEmpty == true ? "&api_key=${booru.apiKey}" : "";
return "${booru.baseURL}/posts.json?tags=$tags&limit=${limit.toString()}&page=${pageNum.toString()}$loginStr$apiKeyStr";
}

Expand All @@ -129,7 +142,8 @@ class DanbooruHandler extends BooruHandler {

@override
String? parseTagSuggestion(responseItem, int index) {
final String tagStr = (responseItem['antecedent'] ?? responseItem['value'])?.toString() ?? "";
final String tagStr =
(responseItem['antecedent'] ?? responseItem['value'])?.toString() ?? "";
if (tagStr.isEmpty) return null;

final String rawTagType = responseItem["category"]?.toString() ?? "";
Expand All @@ -149,7 +163,9 @@ class DanbooruHandler extends BooruHandler {

@override
CommentItem? parseComment(responseItem, int index) {
final String? dateStr = responseItem['created_at']?.toString().substring(0, responseItem['created_at']!.toString().length - 6);
final String? dateStr = responseItem['created_at']
?.toString()
.substring(0, responseItem['created_at']!.toString().length - 6);
return CommentItem(
id: responseItem["id"].toString(),
title: responseItem["post_id"].toString(),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/data/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class Constants {
static String appName = "LoliSnatcher";
// TODO don't forget to update on every new release
// TODO take these from smth like .env?
static String appVersion = "2.3.1";
static int appBuildNumber = 181;
static String appVersion = "2.3.2";
static int appBuildNumber = 182;
//

static const int defaultItemLimit = 20;

static const int tagStaleTime = 3 * 24 * 60 * 60 * 1000; // 3 days

static const String discordURL = 'https://discord.gg/pRNcfTEJ';
}
static const String discordURL = 'https://discord.gg/r9E4HDx9dz';
}
Loading

0 comments on commit c25219d

Please sign in to comment.