Coder Social home page Coder Social logo

pornhub.js's Introduction

PornHub.js

logo

npm License

Powerful PornHub API for Node.js

Features

  • Parser: Parse pages for Video, Album, Photo, PornStar and Model
  • Search: Search for Video, Album, Gif, PornStar and Model, support all the query parameters
  • Pagination: Support pagination for search results
  • WebMaster: Utilize the WebMaster API from Hubtraffic like a king 😎

Documents

Getting Started

Requirements

  • Node.js >= 14

Installation

npm install pornhub.js --save
pnpm install pornhub.js --save
yarn add pornhub.js

Usage

import { PornHub } from 'pornhub.js'

// const { PornHub } = require('pornhub.js')
const pornhub = new PornHub()

Search Video

const result = pornhub.searchVideo('tokyo hot')
console.log(result.data[0]) // first video
Result
{
  "title": "Japanese Tokyo Hot",
  "url": "https://www.pornhub.com/view_video.php?viewkey=***",
  "views": "14M",
  "duration": "14:24",
  "hd": true,
  "premium": false,
  "freePremium": false,
  "preview": "https://ci.phncdn.com/videos/***.jpg"
}

Getting Video Information

const url = 'https://www.pornhub.com/view_video.php?viewkey=ph5ac81eabe203d'
const video = await pornhub.video(url)
console.log(video)
Result
{
  "title": "Japanese Tokyo Hot",
  "views": 49517,
  "duration": 1922,
  "durationFormatted": "32:02",
  "vote": { "up": 64, "down": 14, "total": 78, "rating": 0.82 },
  "premium": false,
  "thumb": "data:image/gif...",
  "provider": { "username": "wowgirls", "url": "/users/wowgirls" },
  "tags": ["hardcore", "hentai", "memes"],
  "categories": ["HD-Porn", "SFW"],
  "pornstars": ["pig"],
  "mediaDefinitions": [
    {
      "defaultQuality": true,
      "format": "hls",
      "quality": 720,
      "videoUrl": "https://cv.phncdn.com/videos/.../720P_1500K_.m3u8?validfrom=...&validto=...&rate=...&burst=...&ip=...&ipa=...&hash=..."
    },
    {
      "defaultQuality": false,
      "format": "hls",
      "quality": [1080, 720, 480, 240],
      "videoUrl": "https://cv.phncdn.com/videos/.../480P_600K_.m3u8?validfrom=...&validto=...&rate=...&burst=...&ip=...&ipa=...&hash=..."
    },
    {
      "defaultQuality": false,
      "format": "hls",
      "quality": 240,
      "videoUrl": "https://cv.phncdn.com/videos/.../240P_400K_.m3u8?validfrom=...&validto=...&rate=...&burst=...&ip=...&ipa=...&hash=...",
      "remote": true
    }
  ]
}

More

See DOCUMENT for more information.

Notice

  • Please note that video downloading is no longer supported. We are unable to provide a download link due to the changes made by PornHub. Instead, the raw mediaDefinitions are provided. You can try to download videos via the m3u8 information in mediaDefinitions or use alternative tools such as yt-dlp. But that would be out of the scope of this project.

License

MIT

pornhub.js's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar j-talas avatar pionxzh 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  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  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  avatar  avatar  avatar  avatar  avatar

pornhub.js's Issues

Got 403 Forbidden with `video`

await pornhub.video(res.id) // Regardless of it being .id or .url

Gave me an error: Error: 403 Forbidden at https://www.pornhub.com/.
res returned:

{
  id: 'ph5f37125f91251',
  url: 'https://www.pornhub.com/view_video.php?viewkey=ph5f37125f91251',
  title: 'Школьницу трахнули в деревне получила сперму внутрь и вагинальный оргазм',
  views: 6700,
  vote: { up: 9, down: 3, total: 12, rating: 0.75 },
  premium: false,
  thumb: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  preview: 'https://ei.phncdn.com/videos/202008/14/342432041/original/(m=eaAaGwObaaaa)(mh=KNnt5M_PHD3nSUch)7.jpg',
  videos: [],
  provider: { username: 'Freken Pussy Snork', url: '/model/freken-pussy-snork' },
  tags: [
    'kink',
    'teenager',
    ' public',
    'outside',
    'teen',
    'village-girl',
    'vaginal-orgasm',
    'real-orgasm',
    'close-up-pussy',
    'close-up-pussy-fuck',
    'close-up-open-pussy',
    'close-up-orgasm',
    'pornhub',
    'plug-anal',
    'pussy-ass'
  ],
  pornstars: [],
  categories: [
    'Amateur',
    'Cumshot',
    'Exclusive',
    'Female-Orgasm',
    'Fetish',
    'HD-Porn',
    'Handjob',
    'Public',
    'School-(18+)',
    'Teen-(18+)',
    'Verified-Amateurs'
  ],
  duration: 55,
  durationFormatted: '00:55',
  uploadDate: 2020-08-14T22:56:14.000Z
}

(I'm on v1.7.1)

Error on heroku

image
This is the error when i use git push heroku main to deploy my app

Get PH models by ranking

Hello,
would it be possible that you could implement a function where I can get all models sorted by their ranking?

Illegal searches

Hey,

I am using this library on a verified Discord bot, where I've seen it sadly being used in malcious ways like searching for illegal prn.
Currently when this occurs the bot just errors. But here's a suggestion:
In case someone searches for something "illegal" like CP or R
pe or other kinds of illegal p*rn, can you make it instead of trying to return results and information about those results (which will error in those cases), make it return something related to this issue.

I know pornhub returns with a special screen in case of illegal searches shown in the screenshots below:
image
image

I think it'd be a good idea to make this library return with at least something in case of illegal searches. E.g. it could return with a simple boolean like illegal_search: true/false and if it's true then also return the reason so the developer can write in their own message for those reasons.

If you need any further explaination, let me know. :)
(Apologies if this is really messy written as I wrote it at 3am)

Search is returning empty/false values

{
  data: [],
  paging: { current: NaN, maxPage: NaN, isEnd: true },
  counting: { from: 0, to: 0, total: 0 }
}

let title = "hentai"
const search = (await pornhub.searchVideo(title))
console.log(search)

The `recommendedVideos` function always returns empty result

For some reason, with or without passing a country, it always returns nothing. ({ data: [], paging: { current: 1, maxPage: 1, isEnd: true } }).
I'm guessing PH made some changes, cause it used to work. I think this started occuring like 1-2 weeks ago, not too sure.

Dependency Dashboard

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

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/check.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/release-please.yml
  • google-github-actions/release-please-action v4
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • cheerio 1.0.0-rc.12
  • debug ^4.3.4
  • node-fetch ^2.7.0
  • urlcat ^3.1.0

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

Return an MP4 link and a Download link when getting a video

I think it'd be useful if videos provided an MP4 link.
In my use case, it'd be better and easier for users of my Discord bot to watch these videos if they could be sent directly to Discord as a video file, instead of only sharing a link. Many of my bot's users have requested this. 🙂

Likewise, I think it'd be cool to have a Download link as well.
In my use case again, I'd be able to make a button with a direct download link, which in my opinion would be really cool!

(3 suggestion in 4 hours, I doubt I can think of more today xD)

align `views` format in `video` and `searchVideo`

Currently views from searchVideo will be formatted to 1.2M
but views from video will be a whole number, e.g. 475000

Consider providing two new fields to align the type and format

  • viewCount: number. e.g. 475000
  • viewCountFormatted: string. e.g. 1.2M

And we can drop views in the next major version

Reference: #68 (comment) #68 (comment)

recommendedVideos() started to have issues

The recommendedVideos() function has started to return objects like this:

{ data: [], paging: { current: NaN, maxPage: NaN, isEnd: true } }

This is happening both on v1.5.0 and v1.5.1.

Age confirmation required

Hi. Lately Pornhub added age confirmation and search now is not working. To fix it just add this 3 lines to buildRequest method

if (!headers.Cookie) {
        headers['Cookie'] = 'accessAgeDisclaimerPH=1; cookiesBannerSeen=1; atatusScript=hide; ';
}

TypeError: urlcat is not a function

Getting the following error

file:///C:/Users/user/phproj/node_modules/pornhub.js/dist/index.mjs:159
var WebmasterBaseUrl = urlcat(BASE_URL, "/webmasters");
                       ^

TypeError: urlcat is not a function
    at file:///C:/Users/user/phproj/node_modules/pornhub.js/dist/index.mjs:159:24
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v19.2.0

Using the following code

import { PornHub } from 'pornhub.js'
const pornhub = new PornHub();

(async () => {
        const result = pornhub.searchVideo('small');
        console.log(result.length);
})()

Currently using release 1.1.0 of pornhub.js. Any clue what the issue could be?

`<pornstar>.mostRecentVideos` returns empty array if no recent UPLOADED videos, but with recent TAGGED videos.

With pornstars, if they don't have any recent UPLOADED videos, the mostRecentVideos property returns an empty array.
For example if trying with https://www.pornhub.com/pornstar/mia-khalifa who obviously has videos, it returns an empty array because she doesn't have any UPLOADED videos, only tagged. The array returns as expected if they DO have recent UPLOADED video(s).

I don't know if this happens to models as well as I haven't been able to find a model with no recent UPLOADED videos but some recent TAGGED videos, since models I think always just uploads their content themselves.

Feature request: `gif(url)` for GIF page

The title says it all lol.
Currently the gifSearch function only returns:

{
  title: 'redheads1',
  url: 'https://www.pornhub.com/gif/19926051',
  mp4: 'https://dl.phncdn.com/pics/gifs/019/926/051/19926051a.mp4',
  webm: 'https://dl.phncdn.com/pics/gifs/019/926/051/19926051a.webm',
  preview: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
}

But if you go to the page, you'll notice that it also has "votes", "views" and the coolest part, "From this video", which links to the video that the gif is from, and even the timestamp. Other than that it also returns "Pornstars", tags and the date (relative format) of upload.

Get Random Video Function

Hey there,
I love this library (as you can probably tell since this isn't my first suggestion xD), and I think it'd be a cool-to-have feature if there was a randomVideo function that would obviously return a random video. 😄 Not just one of the first few "Most Viewed" ones as an example, but completely random.
This could also work with Pstars and Models (randomPornstar & randomModel).
These functions could also take tags as well (optional) that'd return a random video/pstar/model with these tags, but if no tags are provided, just a completely random video/pstar/model.

I don't even know if this is possible and/or if you wanna make it, but worth a try. 😊

Suggestion for a new project

I didn't really know where to request this, so I'll just submit an issue here xd.

Since you made Pornhub.js and that is really easy to use I wanted to ask if you could also make a library for https://tiktits.com where you'd be able to get a random video / search for a video and return a result the same way Pornhub.js returns results 😄

searchModel errors

How I'm using it:

let pornhubSearch = 'candy love' // just an example
await pornhub.searchModel(pornhubSearch) // btw this is line 172 in my code

Error:

error

How to use this package without vpn

Because pornhub site Block in my country. Indonesia . And I can't embed pornhub videos. I have tried with node-unblocker to embed video but it is not working. is there a way to overcome that

Videos Returning 403 When Running on Heroku

Hey, thanks for this package!

I have an API using this package running locally which works great. When I push it to heroku and request a video, the video files return 403 for some reason...

Any idea as to why this might be happening?

Video been redirected to a corn video

Latest Update

This has been automatically handled since v1.1.0.

Outdated

See this corn video again and again?

Tons of hard cobs getting grabbed

Solutions

with top-level await

const pornhub = new Pornhub()
// make this the first call
await pornhub.warmup()

// some other calls
// await pornhub.video(url)

or without top-level await

const pornhub = new Pornhub()

(async() => {
  // make this the first call
  await pornhub.warmup()

  // some other calls
  // const result = await pornhub.video(url)
})()

For more information, please check warmup()

Original Questions

No matter what video you are trying to download, it will be redirected to the same corn video...

Tons of hard cobs getting grabbed

it might be caused by some anti-crawler things on Pornhub, you will need to use a VPN to bypass it.
At first, I thought they flagged my IP because of the E2E testing 🤣
But it's totally fine for me to watch them on a normal browser so... IDK

Related:

`searchVideo` got empty result

Whatever what I search for, the searchVideo function always returns

{
  data: [],
  paging: { current: NaN, maxPage: NaN, isEnd: true },
  counting: { from: 0, to: 0, total: 0 }
}

I even tried to search for something as simple as "ass" which Pornhub should contain lots of xD, but no results?

Package does not work with CommonJS

Code

const {Pornhub} = require('pornhub.js);`
const pornhub = new PornHub();
const result = pornhub.searchGif('ass');
console.log(result.data[0]);

Error:

var import_node_fetch = __toESM(require("node-fetch"));
                                ^

Error [ERR_REQUIRE_ESM]: require() of ES Module

Appears to be a git repo or submodule.

Error:
npm ERR! code EISGIT
npm ERR! path C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js
npm ERR! git C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js: Appears to be a git repo or submodule.
npm ERR! git C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

and i cant install any npm modules

yt-dlp

Just had to poke in an fyi for the lacking video download. I'm pretty sure yt-dlp can handle practically anything. 😉

AI video training soon much? 😜

Add support for searching PH models

Is it possible to do so it can also search for PH models and not only pornstars? Because Sometimes when searching for pornstars who turns how to be a model, it gets someone completely different

error

Error:
npm ERR! code EISGIT
npm ERR! path C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js
npm ERR! git C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js: Appears to be a git repo or submodule.
npm ERR! git C:\Users\RDev\Desktop\dev\dpb\node_modules\pornhub.js
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

and i cant install any npm modules

Support the endpoint "/video?o=?"

This could e.g be used to find the hottest videos.

https://www.pornhub.com/video?o=ht finds the hottest videos world wide.
You can also get it country based. For example, you can use the endpoint /video?o=ht&cc=dk which finds the hottest videos in Denmark. I do not know all the countries, but then I'd assume "cc=uk" is the hottest videos in the United Kingdom" and "cc=us" in the United States and etc.

It can also be used to find:

  • Most Viewed (o=mv) which also supports the country configs
  • Top Rated (o=tr)
  • Newest (o=cm)

Then I also think it'd be cool to support the /recommended endpoint. Even though this is personlized, I hope there'd be some sort of work-around for this.

Issue with the randomVideo function

Hey there,

I just tried out the randomVideo function and it doesn't really seem to return the same data as a video from for example searchVideo.
For example; the result's preview doesn't exist, instead there's thumb which returns something rather useless. At least, I have no idea how to convert it to an image url.
thumb: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',

Another thing, the views aren't formatted like videos from searchVideo either. Those will return e.g. "1.2M", but the randomVideo function will return a whole number. Maybe also return a formatted version, otherwise I have no issue with using:

function nFormatter(num) {
    if (num >= 1000000000) {
        return (num / 1000000000).toFixed(1).replace(/\.0$/, '') + 'B';
    }
    if (num >= 1000000) {
        return (num / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
    }
    if (num >= 1000) {
        return (num / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
    }
    return num;
}

That's just a matter of wanting my code to look clean. :)

I also had an encounter where the randomVideo function didn't even return a video, but instead the normal PH homepage xD

Minor issue with recommendedVideos()

Hey there,

When I get a random video from the searchVideo() function, it returns the result.preview perfectly fine. But I noticed that with recommendedVideos() when getting a random video, it returns the result.preview but in a way smaller size. This happens every time and looks really ugly in an embed.

InkedInkedcc355ebd2379a3ffa0a9523d6f4ebe37

Randomly got an error from random()

Error:

Error: 403 Forbidden at https://www.pornhub.com/random`
 at Request.checkStatus (C:\Users\Administrator\Desktop\...\...\node_modules\pornhub.js\dist\index.js:613:27)

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.