@ikenxuan/amagi
使用指南

SDK 使用指南

详细了解如何使用 amagi SDK

SDK 使用指南

amagi 提供了灵活的 SDK 调用方式,支持多种使用模式。

客户端实例模式(推荐)

创建客户端实例后,可以直接调用各平台的 fetcher API,无需重复传递 cookie。

import  from '@ikenxuan/amagi'

const  = ({
  : {
    : 'your_bilibili_cookie',
    : 'your_douyin_cookie',
    : 'your_kuaishou_cookie',
    : 'your_xiaohongshu_cookie',
  }
})

// 使用 fetcher API
const  = await ...({ : 'BV1xx411c7mD' })
const  = await ...({ : '123456789' })

静态 Fetcher 模式

如果不想创建实例,可以使用静态 fetcher,但需要手动传递 cookie:

import  from '@ikenxuan/amagi'

const  = await ..(
  { : 'BV1xx411c7mD' }, 
  'SESSDATA=xxx; bili_jct=yyy'
)

工厂函数模式

使用 createBound*Fetcher 工厂函数创建绑定 cookie 的 fetcher:

import  from '@ikenxuan/amagi'

// 创建绑定 cookie 的 fetcher
const  = .('your_cookie')
const  = .('your_cookie')

// 调用时无需传递 cookie
const  = await .({ : 'BV1xx411c7mD' })

统一响应格式

所有 API 返回统一的 Result<T> 结构:

type <> = {
  : true
  : number
  : string
  : 
}

type  = {
  : false
  : number
  : string
  : any
}

type <> = <> | 

使用示例

const  = await ...({ : 'BV1xx411c7mD' })

if (.) {
  // 成功处理
  .(.)
} else {
  // 错误处理
  .(., .)
}

请求配置

可以在创建客户端时传递自定义请求配置:

import  from '@ikenxuan/amagi'

const  = ({
  : {
    : 'your_cookie',
    : 'your_cookie',
    : 'your_cookie',
    : 'your_cookie',
  },
  : {
    : {
      'User-Agent': 'Mozilla/5.0 ...',
    },
    : 10000,
    : {
      : '127.0.0.1',
      : 7890,
    }
  }
})

平台模块结构

每个平台模块包含以下内容:

// fetcher - 数据获取器
...({ : 'BV1xx' })
...({ : '123', : 1 })
...({ : 123456 })

// sign - 签名算法
...(170001)
...('BV1xx411c7mD')

// danmaku - 弹幕解析
// client.bilibili.danmaku.parseDmSegMobileReply(buffer)
// fetcher - 数据获取器
...({ : '123' })
...({ : '123' })
...({ : '123' })

// sign - 签名算法
...(128)
// client.douyin.sign.AB(url, ua)
// client.douyin.sign.XB(url, ua)
// fetcher - 数据获取器
...({ : '3xq123' })
...({ : '3xq123' })
...({})
// fetcher - 数据获取器
...({ : '123', : 'xxx' })
...({ : '123', : 'xxx' })
...({ : '123' })

// sign - 签名算法
// client.xiaohongshu.sign.generateXSGet(path, a1Cookie)

On this page