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,29 +54,29 @@ class Post {
return this.post.file_url
}
def getSampleImageUrl() {
return this.post.large_file_url
}
def getSampleImageUrl() = this.post.large_file_url
def containsTags(tags) = stream(tags)
.anyMatch(def(t) = arrayKeyExists(t, this.tags))
def getScore() = int(this.post.score ?? 0)
def getArtists() {
return match int(this.post.tag_count_artist ?? 0) {
case 0: []
case 1: [this.post.tag_string_artist]
case _: this.post.tag_string_artist.split(" ")
}
def getArtists() = match int(this.post.tag_count_artist ?? 0) {
case 0: []
case 1: [this.post.tag_string_artist]
case _: this.post.tag_string_artist.split(" ")
}
def getCharacters() {
return match int(this.post.tag_count_character ?? 0) {
case 0: []
case 1: [this.post.tag_string_character]
case _: this.post.tag_string_character.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() = match int(this.post.tag_count_character ?? 0) {
case 0: []
case 1: [this.post.tag_string_character]
case _: this.post.tag_string_character.split(" ")
}
def getSource() {

View File

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