Giter VIP home page Giter VIP logo

pixiv's Introduction

pixiv client for go

godev build status

Pixiv go 客户端, 使用 PIXIV 网页 API。

设计文档

  • 画作搜索
  • 画作排行榜
  • 画作详情
  • 小说搜索
  • 小说排行榜
  • 小说详情
  • 渲染小说为 HTML
  • 用户详情

详细使用方法以代码注释为准

package main

import (
    "context"

    "github.com/NateScarlet/pixiv/pkg/client"
    "github.com/NateScarlet/pixiv/pkg/artwork"
    "github.com/NateScarlet/pixiv/pkg/novel"
    "github.com/NateScarlet/pixiv/pkg/user"
)

// 默认客户端用环境变量 `PIXIV_PHPSESSID` 登录。
// 并且 User-Agent 使用 `PIXIV_USER_AGENT` 或库内置的默认值。
client.Default

// 使用 PHPSESSID Cookie 登录 (推荐)。
c := &client.Client{}
c.SetDefaultHeader("User-Agent", client.DefaultUserAgent)
c.SetPHPSESSID("PHPSESSID")

// 通过账号密码登录(可能触发 reCAPTCHA)。
c := &client.Client{}
c.SetDefaultHeader("User-Agent", client.DefaultUserAgent)
c.Login("username", "password")

// 启用免代理,环境变量 `PIXIV_BYPASS_SNI_BLOCKING` 不为空时自动为默认客户端启用免代理。
// 当前实现需求一个 DNS over HTTPS 服务,默认使用 cloudflare,可通过 `PIXIV_DNS_QUERY_URL` 环境变量设置。
// 必须在其他客户端选项前调用 `BypassSNIBlocking`,因为对于封锁的域名它会使用一个更改过的 Transport 进行请求,无视在它之前进行的的设置。
c := &client.Client{}
c.BypassSNIBlocking()
c.SetDefaultHeader("User-Agent", client.DefaultUserAgent)

// 所有查询从 context 获取客户端设置, 如未设置将使用默认客户端。
var ctx = context.Background()
ctx = client.With(ctx, c)

// 搜索画作
result, err := artwork.Search(ctx, "パチュリー・ノーレッジ")
result.JSON // json return data.
result.Artworks() // []artwork.Artwork,只有部分数据,通过 `Fetch` `FetchPages` 方法获取完整数据。
artwork.Search(ctx, "パチュリー・ノーレッジ", artwork.SearchOptionPage(2)) // 获取第二页

// 画作详情
i := &artwork.Artwork{ID: "22238487"}
err := i.Fetch(ctx) // 获取画作详情(不含分页), 直接更新 struct 数据。
err := i.FetchPages(ctx) // 获取画作分页, 直接更新 struct 数据。

// 画作排行榜
rank := &artwork.Rank{Mode: "daily"}
rank.Fetch(ctx)
rank.Items[0].Rank
rank.Items[0].PreviousRank
rank.Items[0].Artwork

// 搜索小说
result, err := novel.Search(ctx, "パチュリー・ノーレッジ")
result.JSON // json return data.
result.Novels() // []novel.Novel,只有部分数据,通过 `Fetch` 方法获取完整数据。
novel.Search(ctx, "パチュリー・ノーレッジ", novel.SearchOptionPage(2)) // 获取第二页

// 小说详情
i := &novel.Novel{ID: "11983096"}
err := i.Fetch(ctx) // 获取小说详情, 直接更新 struct 数据。

// 用户详情
i := &user.User{ID: "789096"}
err := i.Fetch(ctx) // 获取用户详情, 直接更新 struct 数据。

pixiv's People

Contributors

abserari avatar github-actions[bot] avatar natescarlet avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pixiv's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/go.yml
  • actions/setup-go v3
  • actions/checkout v3
.github/workflows/release-please.yml
  • google-github-actions/release-please-action v3
gomod
go.mod
  • go 1.13
  • github.com/NateScarlet/snapshot v0.6.0
  • github.com/PuerkitoBio/goquery v1.8.1
  • github.com/stretchr/testify v1.8.2
  • github.com/tidwall/gjson v1.17.1

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.