MCPcopy Create free account
hub / github.com/FloatTech/AnimeAPI / Works

Function Works

pixiv/pixiv.go:28–74  ·  view source on GitHub ↗

Works 获取插画信息

(id int64)

Source from the content-addressed store, hash-verified

26
27// Works 获取插画信息
28func Works(id int64) (i *Illust, err error) {
29 data, err := get("https://www.pixiv.net/ajax/illust/" + strconv.FormatInt(id, 10))
30 if err != nil {
31 return nil, err
32 }
33 json := gjson.ParseBytes(data).Get("body")
34 // 如果有"R-18"tag则判断为R-18(暂时)
35 var ageLimit = "all-age"
36 for _, tag := range json.Get("tags.tags.#.tag").Array() {
37 if tag.Str == "R-18" {
38 ageLimit = "r18"
39 break
40 }
41 }
42 // 解决json返回带html格式
43 var caption = strings.ReplaceAll(json.Get("illustComment").Str, "<br />", "\n")
44 if index := strings.Index(caption, "<"); index != -1 {
45 caption = caption[:index]
46 }
47 // 解析返回插画信息
48 i = &Illust{}
49 i.Pid = json.Get("illustId").Int()
50 i.Title = json.Get("illustTitle").Str
51 i.Caption = caption
52 i.Tags = fmt.Sprintln(json.Get("tags.tags.#.tag").Array())
53 orgs := json.Get("urls.original")
54 if orgs.Type != gjson.Null {
55 u := strings.ReplaceAll(orgs.Str, "_p0.", "_p%d.")
56 for j := 0; j < int(json.Get("pageCount").Int()); j++ {
57 i.ImageUrls = append(i.ImageUrls, fmt.Sprintf(u, j))
58 }
59 } else { // try third-party API
60 g, err := Cat(id)
61 if err == nil {
62 if g.Multiple {
63 i.ImageUrls = g.OriginalUrls
64 } else {
65 i.ImageUrls = []string{g.OriginalURL}
66 }
67 }
68 }
69 i.AgeLimit = ageLimit
70 i.CreatedTime = json.Get("createDate").Str
71 i.UserID = json.Get("userId").Int()
72 i.UserName = json.Get("userName").Str
73 return i, err
74}
75
76// RankValue 搜索元素
77type RankValue struct {

Callers 2

YandexFunction · 0.92
TestDownloadToCacheFunction · 0.85

Calls 2

getFunction · 0.85
CatFunction · 0.85

Tested by 1

TestDownloadToCacheFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…