Clean-up hashtag

This commit is contained in:
aNNiMON 2024-08-11 18:57:47 +03:00
parent dabb0b95ab
commit 6df64a9a7b
2 changed files with 37 additions and 28 deletions

View File

@ -54,30 +54,30 @@ class Post {
return this.post.file_url return this.post.file_url
} }
def getSampleImageUrl() { def getSampleImageUrl() = this.post.large_file_url
return this.post.large_file_url
}
def containsTags(tags) = stream(tags) def containsTags(tags) = stream(tags)
.anyMatch(def(t) = arrayKeyExists(t, this.tags)) .anyMatch(def(t) = arrayKeyExists(t, this.tags))
def getScore() = int(this.post.score ?? 0) def getScore() = int(this.post.score ?? 0)
def getArtists() { def getArtists() = match int(this.post.tag_count_artist ?? 0) {
return match int(this.post.tag_count_artist ?? 0) {
case 0: [] case 0: []
case 1: [this.post.tag_string_artist] case 1: [this.post.tag_string_artist]
case _: this.post.tag_string_artist.split(" ") case _: this.post.tag_string_artist.split(" ")
} }
def getCopyrights() = match int(this.post.tag_count_copyright ?? 0) {
case 0: []
case 1: [this.post.tag_string_copyright]
case _: this.post.tag_string_copyright.split(" ")
} }
def getCharacters() { def getCharacters() = match int(this.post.tag_count_character ?? 0) {
return match int(this.post.tag_count_character ?? 0) {
case 0: [] case 0: []
case 1: [this.post.tag_string_character] case 1: [this.post.tag_string_character]
case _: this.post.tag_string_character.split(" ") case _: this.post.tag_string_character.split(" ")
} }
}
def getSource() { def getSource() {
src = this.post.source src = this.post.source

View File

@ -26,9 +26,7 @@ blacklistTags = config.danbooru.blacklistTags
for post : filteredPosts { for post : filteredPosts {
// Check global blacklist // Check global blacklist
blacklisted = post.containsTags(blacklistTags) blacklisted = post.containsTags(blacklistTags)
if (blacklisted) { if (blacklisted) continue
continue
}
score = post.getScore() score = post.getScore()
for target : config.targets { for target : config.targets {
@ -80,17 +78,28 @@ def strToHashtag(str) =
.replaceAll("[^a-z_0-9\s]", "") .replaceAll("[^a-z_0-9\s]", "")
.replaceAll("\s+", "_") .replaceAll("\s+", "_")
def getCaption(post) { def getCharacterHashtags(post) {
characters = post.getCharacters() characters = post.getCharacters()
if characters.length > 0 { if characters.isEmpty() {
charactersHashTag = map(characters, ::strToHashtag).joinToString(" ") return "#original"
} else {
charactersHashTag = "#original"
} }
sourceUrl = post.getSource() copyrights = post.getCopyrights()
return "%s | <a href=\"%s\">source</a>".sprintf( hashtags = []
charactersHashTag, for character : characters {
sourceUrl hashtag = strToHashtag(character)
) // Clean-up copyright suffix
for copyright : copyrights {
replaceFrom = "_" + copyright
hashtag = hashtag.replace(replaceFrom, "")
}
hashtags += hashtag
}
return hashtags.joinToString(" ")
} }
def getCaption(post) = sprintf(
"%s | <a href=\"%s\">source</a>",
getCharacterHashtags(post),
post.getSource()
)