npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pornhub-api

v1.0.7

Published

重构请求,新增随机真实header

Readme

Pornhub API

一个功能完整的 Pornhub API 包装器,支持账号管理、视频数据获取和评论互动功能。

安装

npm install pornhub-api

快速开始

使用类方式(推荐)

const { PornhubAPI } = require("pornhub-api");

const client = new PornhubAPI({
  proxy: "your-proxy-url", // 可选
  userAgent: "custom-user-agent", // 可选
});

// 账号登录
async function loginExample() {
  try {
    const result = await client.account.login("[email protected]", "password");
    console.log("登录成功:", result);
  } catch (error) {
    console.error("登录失败:", error.message);
  }
}

// 获取视频详情
async function getVideoExample() {
  try {
    const video = await client.video.getDetail("ph5e8f9c9e2c3d7");
    console.log("视频详情:", video);
  } catch (error) {
    console.error("获取失败:", error.message);
  }
}

// 获取评论
async function getCommentsExample() {
  try {
    const comments = await client.comment.getByTime("video_id");
    console.log("评论列表:", comments);
  } catch (error) {
    console.error("获取失败:", error.message);
  }
}

使用独立函数

const {
  login,
  getVideoDetail,
  getVideoCommentsByTime,
} = require("pornhub-api");

// 登录
const loginResult = await login("[email protected]", "password");

// 获取视频详情
const video = await getVideoDetail("ph5e8f9c9e2c3d7", "cookie");

// 获取评论
const comments = await getVideoCommentsByTime("video_id", "cookie");

API 文档

账号管理 (client.account)

login(email, password)

用户登录

  • email: 邮箱地址
  • password: 密码
  • 返回: 包含 cookie、username、token 的登录信息

getToken(cookie)

获取用户 token

  • cookie: 用户 cookie
  • 返回: token 和 session cookie

getVerifyCaptcha(email, token, cookie)

获取邮箱验证码

  • email: 邮箱地址
  • token: 用户 token
  • cookie: 用户 cookie
  • 返回: 验证码发送结果

verify(code, token, cookie)

验证邮箱验证码

  • code: 验证码
  • token: 用户 token
  • cookie: 用户 cookie
  • 返回: 验证结果

finishGuideTour(token, cookie)

完成新手引导

  • token: 用户 token
  • cookie: 用户 cookie
  • 返回: 操作结果

watchVideo(vkey, cookie)

模拟观看视频

  • vkey: 视频 key
  • cookie: 用户 cookie
  • 返回: 操作结果

视频相关 (client.video)

getDetail(vkey, cookie?)

获取视频详情

  • vkey: 视频 key
  • cookie: 用户 cookie(可选)
  • 返回: 视频详细信息

getPopularVideos(query)

获取热门视频列表

  • query: 查询参数对象
  • 返回: 视频列表数组

评论相关 (client.comment)

getByTime(vid, cookie?)

获取视频评论(按时间排序)

  • vid: 视频 ID
  • cookie: 用户 cookie(可选)
  • 返回: 评论列表

getMostPopular(vid, cookie?)

获取最热门评论

  • vid: 视频 ID
  • cookie: 用户 cookie(可选)
  • 返回: 热门评论信息

voteUp(cid, token, cookie)

给评论点赞

  • cid: 评论 ID
  • token: 用户 token
  • cookie: 用户 cookie
  • 返回: 点赞结果

post(vid, vkey, content, token, cookie, captcha?, ua?, agent?)

发布评论

  • vid: 视频 ID
  • vkey: 视频 key
  • content: 评论内容
  • token: 用户 token
  • cookie: 用户 cookie
  • captcha: 验证码(可选)
  • ua: 用户代理(可选)
  • agent: 自定义用户代理(可选)
  • 返回: 发布结果

环境变量

可以通过环境变量进行详细配置。首先复制 .env.example 文件为 .env 并填写实际值:

cp .env.example .env
# 编辑 .env 文件,填写你的代理信息和其他配置

必需环境变量

# 代理配置(必需)
export PORNHUB_PROXY_HOST="your-proxy-host"
export PORNHUB_PROXY_PORT="your-proxy-port"
export PORNHUB_PROXY_USERNAME="your-proxy-username"
export PORNHUB_PROXY_PASSWORD="your-proxy-password"

可选环境变量

# 基础配置
export PORNHUB_BASE_URL="https://www.pornhub.com"  # 默认值
export PORNHUB_TIMEOUT="10000"  # 请求超时时间(毫秒),默认 10000
export PORNHUB_DEFAULT_COOKIE="accessAgeDisclaimerPH=1"  # 默认 cookie,默认 accessAgeDisclaimerPH=1
export PORNHUB_USER_AGENT="Mozilla/5.0 ..."  # 自定义 User-Agent,默认使用随机生成

# 登录相关
export PORNHUB_LOGIN_FROM="pc_login_modal_:index"  # 登录来源,默认 pc_login_modal_:index
export PORNHUB_LOGIN_REDIRECT="..."  # 登录重定向 URL,默认内置值

# 注册相关
export PORNHUB_SIGNUP_REDIRECT=""  # 注册重定向,默认空
export PORNHUB_SIGNUP_SHOW_ONBOARDING="1"  # 显示引导,默认 1
export PORNHUB_SIGNUP_MODAL="true"  # 模态框注册,默认 true

# 验证码相关
export PORNHUB_CAPTCHA_TYPE="checkbox"  # 验证码类型,默认 checkbox

# 视频相关
export PORNHUB_VIDEO_COOKIE="platform=pc; language=en"  # 视频页面 cookie,默认 platform=pc; language=en

错误处理

所有方法都会抛出错误,建议使用 try-catch 进行错误处理:

try {
  const result = await client.account.login(email, password);
  // 处理成功结果
} catch (error) {
  console.error("操作失败:", error.message);
  // 处理错误
}

注意事项

  1. 使用代理可以提高成功率和避免 IP 封禁
  2. 部分功能需要登录后的 cookie 和 token
  3. 请遵守网站的使用条款和 API 限制
  4. 建议适当添加请求间隔避免频率限制

许可证

MIT