SoutuBot

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 16 Imported by: 0

README

SoutuBot-go

要求

  • Go 1.25+
  • 运行中的 FlareSolverr 服务端 (fsClient 传 nil 也能跑, 能不能用看 IP 质量)

安装

go get github.com/Miuzarte/SoutuBot-go

示例

package main

import (
    "context"
    "fmt"
    fs "github.com/Miuzarte/FlareSolverr-go"
    stb "github.com/Miuzarte/SoutuBot-go"
)

func main() {
    fsClient := fs.NewClient("http://127.0.0.1:8191/v1")
    client := stb.NewClient(fsClient)
    ctx := context.Background()

    var imgData []byte // raw png/jpg/webp
    resp, err := client.Search(ctx, imgData)
    if err != nil {
        panic(err)
    }

    // 获取之前的搜索结果
    const id = "2026011412270786"
    // resp, err := client.GetResult(ctx, id)

    fmt.Printf("上传的原图片: %s\n", resp.ImageUrl)
    fmt.Printf(
        "耗时 %.2fs\n%s\n找到了 %d 条相似的结果\n",
        resp.ExecutionTime,
        resp.SearchOption,
        len(resp.Data),
    )
    if len(resp.Data) == 0 {
        return
    }
    if resp.Data[0].Similarity < stb.MATCH_SIMILARITY_THRESHOLD {
        fmt.Println("最大匹配度低于45,结果可能不正确")
        fmt.Println("请自行判断,或更换严格模式/其他搜图引擎来搜索")
    }

    var lastI int
    for i, item := range resp.Data {
        if item.Similarity < stb.LOW_SIMILARITY_THRESHOLD {
            // 匹配度必定按从大到小排序
            if i > 3 {
                // 保留前三条低匹配度结果, 剩余的不展示
                break
            }
        }

        var hosts []string = item.Source.Hosts()
        // [0]: "https://nhentai.net"  / [1]: "https://nhentai.xxx"
        // [0]: "https://e-hentai.org" / [1]: "https://exhentai.org"
        // [0]: "https://panda.chaika.moe"

        fmt.Printf(
            "[%d] %s\n匹配度: %.2f%%\n语言: %s\n来源: %s\n",
            i, item.Title,
            item.Similarity,
            item.Language.Emoji(),
            item.Source,
        )
        fmt.Printf("详情页1: %s\n", hosts[0]+item.SubjectPath)
        if len(hosts) >= 2 {
            fmt.Printf("详情页2: %s\n", hosts[1]+item.SubjectPath)
        }
        fmt.Printf("图片页1: %s\n", hosts[0]+item.PagePath)
        if len(hosts) >= 2 {
            fmt.Printf("图片页2: %s\n", hosts[1]+item.PagePath)
        }

        lastI = i
    }

    if lastI+1 < len(resp.Data) {
        fmt.Printf("未显示剩余低匹配度结果(%d条)\n", len(resp.Data)-lastI-1),
    }
}

Documentation

Index

Constants

View Source
const (
	MAIN_PAGE_URL = `https://soutubot.moe`
	API_URL       = `https://soutubot.moe/api/search`
)
View Source
const (
	WEBKIT_BOUNDARY_PREFIX     = "----WebKitFormBoundary" // +"xb1PFceXlCoUBXX8"(16)
	WEBKIT_BOUNDARY_SUFFIX_LEN = 16
)
View Source
const (
	MATCH_SIMILARITY_THRESHOLD = 45.0 // 最大匹配度低于45,结果可能不正确\n请自行判断,或更换严格模式/其他搜图引擎来搜索
	LOW_SIMILARITY_THRESHOLD   = 30.0 // 被隐藏
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	FlareSolverrClient *fs.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(fsClient *fs.Client) *Client

func (*Client) GetResult

func (c *Client) GetResult(ctx context.Context, id string) (*Response, error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, imgData []byte) (*Response, error)

type HttpError

type HttpError struct {
	StatusCode int
	Url        string
	Body       string
}

func (*HttpError) Error

func (e *HttpError) Error() string

type Item

type Item struct {
	Source          Source   `json:"source"` // "nhentai"|"ehentai"|"panda"
	Page            int      `json:"page"`
	Title           string   `json:"title"`
	Language        Language `json:"language"`    // "cn"|"jp"
	PagePath        string   `json:"pagePath"`    // /g/480041/7 | .Source == "panda" => null
	SubjectPath     string   `json:"subjectPath"` // /g/480041
	PreviewImageUrl string   `json:"previewImageUrl"`
	Similarity      float64  `json:"similarity"` // 低匹配度阈值为 30
}

type Language

type Language string

func (Language) Emoji

func (l Language) Emoji() string

type Response

type Response struct {
	Data          []Item  `json:"data"`
	Id            string  `json:"id"`            // "2025102006392555" //  https://soutubot.moe/results/{.Id}
	Factor        float64 `json:"factor"`        // 1.2
	ImageUrl      string  `json:"imageUrl"`      // "https:\/\/img.76888268.xyz\/img\/8ed83259e082ce11285d13ce38718244.webp"
	SearchOption  string  `json:"searchOption"`  // "api 1.2 Liner 64 400x"
	ExecutionTime float64 `json:"executionTime"` // 耗时 (s)
}

type Source

type Source string

func (Source) Hosts

func (s Source) Hosts() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL