feat(submission): parse FA's prefixed system tags into CategorizedTags

FA renders its species/character/artist/type system tags as tag-block
anchors with a data-tag-name carrying a single-letter prefix
(s_/c_/a_-u_/t_) and a sibling tag-invalid span instead of a /search/
link. The existing keyword pass skips them, so they were lost.

Adds a Submission.CategorizedTags field exposing the four buckets with
the prefix stripped, plus an examples/categorized_tags runnable demo.
This commit is contained in:
2026-06-02 21:15:30 +02:00
parent 02479212bc
commit 20fcad7fbb
4 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
// categorized_tags demonstrates how the SDK groups FA's prefixed system
// tags into the four CategorizedTags buckets: Species (s_), Characters (c_),
// Artists (a_/u_), and Types (t_). Each bucket is printed on its own so the
// example covers every aspect of the feature.
//
// Runs anonymously by default. Set FA_A / FA_B (and ideally CF_CLEARANCE +
// FA_UA) to authenticate when the target submission requires it.
//
// go run ./examples/categorized_tags 12345678
package main
import (
"context"
"fmt"
"log"
"os"
"strconv"
"strings"
fa "git.anthrove.art/public/go-fa-api"
)
func main() {
if len(os.Args) < 2 {
log.Fatalf("usage: %s <submission-id>", os.Args[0])
}
id, err := strconv.ParseInt(os.Args[1], 10, 64)
if err != nil {
log.Fatalf("invalid submission id: %v", err)
}
opts := []fa.Option{fa.WithUserAgent("go-fa-api-example/0.1")}
if a, b := os.Getenv("FA_A"), os.Getenv("FA_B"); a != "" && b != "" {
log.Printf("using FA_A/FA_B cookies for authenticated request")
opts = []fa.Option{
fa.WithCookies(fa.Cookies{A: a, B: b}),
fa.WithCloudflare(fa.CFCookies{Clearance: os.Getenv("CF_CLEARANCE")}),
fa.WithUserAgent(envOr("FA_UA", "go-fa-api-example/0.1")),
}
}
client := fa.New(opts...)
sub, err := client.GetSubmission(context.Background(), fa.SubmissionID(id))
if err != nil {
log.Fatalf("GetSubmission: %v", err)
}
fmt.Printf("%s\nby %s\n\n", sub.Title, sub.Author.DisplayName)
fmt.Println("=== Plain keyword tags (no prefix) ===")
if len(sub.Tags) == 0 {
fmt.Println(" (none)")
} else {
fmt.Println(" " + strings.Join(sub.Tags, ", "))
}
ct := sub.CategorizedTags
fmt.Println()
fmt.Println("=== Species (s_) ===")
printBucket(ct.Species, "s_")
fmt.Println()
fmt.Println("=== Characters (c_) ===")
printBucket(ct.Characters, "c_")
fmt.Println()
fmt.Println("=== Artists (a_ / u_) ===")
printBucket(ct.Artists, "a_")
fmt.Println()
fmt.Println("=== Types (t_) ===")
printBucket(ct.Types, "t_")
}
func printBucket(items []string, prefix string) {
if len(items) == 0 {
fmt.Println(" (none)")
return
}
for _, v := range items {
fmt.Printf(" %s%s\n", prefix, v)
}
}
func envOr(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}