pionxzh / Pornhub.js

Powerful PornHub API for Node.js
MIT License
90 stars 19 forks source link

The `recommendedVideos` function always returns empty result #92

Closed iced-queen closed 10 months ago

iced-queen commented 10 months ago

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.

pionxzh commented 10 months ago

Can you provide a reproduction code? I just tested and it works ok. Did you see any error messages?

iced-queen commented 10 months ago

I'm on the latest version by the way.

await pornhub.recommendedVideos(countryObj).then(res => {
     console.log(res)
     result = res.data[Object.keys(res.data)[Math.floor(Math.random() * Object.keys(res.data).length)]]
})

countryObj was { country: 'uk' }. Even without the countryObj I get the same empty result.

I don't see any error messages.

pionxzh commented 10 months ago
  1. Btw, recommendedVideos does not support country parameter, but it's not an issue~
  2. Can you try to enable the debug log with set DEBUG=* & node ./src/index.js, test it locally, and provide the full log?
iced-queen commented 10 months ago
  1. It doesn't? Which function is it that does then (if any)? Is it possible for you to add support for this?
  2. Log from startup:

    REQUEST [Header] Set: Host=www.pornhub.com +0ms
    REQUEST [Header] Set: Origin=https://www.pornhub.com +8ms
    REQUEST [Header] Set: Referer=https://www.pornhub.com/ +8ms
    REQUEST [Header] Set: User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 +6ms
    REQUEST [Cookie] Set: platform=pc +7ms
    REQUEST [Cookie] Set: accessAgeDisclaimerPH=1 +9ms
    REQUEST [Cookie] Set: accessAgeDisclaimerUK=1 +5ms
    REQUEST [Cookie] Set: accessPH=1 +10ms
    REQUEST [Cookie] Set: age_verified=1 +6ms
    REQUEST [Cookie] Set: atatusScript=hide +5ms
    REQUEST [Cookie] Set: cookiesBannerSeen=1 +9ms
    REQUEST [Cookie] Set: hasVisited=1 +3ms

    Log when using the function:

    REQUEST [ RQST ] GET https://www.pornhub.com/recommended +2m
    REQUEST [ RESP ] GET https://www.pornhub.com/recommended 200 OK +81ms
    REQUEST [Cookie] Received Set-Cookie: ss=824159885142554267; expires=Wed, 23-Oct-2024 16:17:59 GMT; Max-Age=31536000; path=/; domain=pornhub.com; secure +1ms
    REQUEST [Cookie] Received Set-Cookie: fg_0d2ec4cbd943df07ec161982a603817e=66256.100000; expires=Thu, 23-Nov-2023 16:17:59 GMT; Max-Age=2592000; path=/; domain=pornhub.com; secure +9ms
    REQUEST [Cookie] Received Set-Cookie: hasVisited=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=www.pornhub.com; secure +4ms
    REQUEST [Cookie] Received Set-Cookie: hasVisited=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +3ms
    REQUEST [Cookie] Received Set-Cookie: hasVisited=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=pornhub.com; secure +2ms
    REQUEST [Cookie] Received Set-Cookie: hasVisited=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +3ms
    REQUEST [Cookie] Received Set-Cookie: __s=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=www.pornhub.com; secure +3ms
    REQUEST [Cookie] Received Set-Cookie: __s=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +3ms
    REQUEST [Cookie] Received Set-Cookie: __s=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=pornhub.com; secure +8ms
    REQUEST [Cookie] Received Set-Cookie: __s=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +5ms
    REQUEST [Cookie] Received Set-Cookie: __l=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=www.pornhub.com; secure +3ms
    REQUEST [Cookie] Received Set-Cookie: __l=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +7ms
    REQUEST [Cookie] Received Set-Cookie: __l=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=pornhub.com; secure +4ms
    REQUEST [Cookie] Received Set-Cookie: __l=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure +6ms
    REQUEST [Cookie] Received Set-Cookie: fg_9951ce1ac4434b4ac312a1334fa77d82=28113.100000; expires=Thu, 23-Nov-2023 16:17:59 GMT; Max-Age=2592000; path=/; domain=pornhub.com; secure +7ms
    REQUEST [Cookie] Received Set-Cookie: __s=6537EE37-42FE722901BB170122-29F28C0; Secure; Samesite=None +4ms
    REQUEST [Cookie] Received Set-Cookie: __l=6537EE37-42FE722901BB170122-29F28C0; Secure; Samesite=None; Max-Age=31556926 +4ms

    And this gave an empty result.

pionxzh commented 10 months ago

It's very weird that you received so many deleted cookies.

pionxzh commented 10 months ago

Only videoList support country, recommendedVideos page don't even have options for you to choose country 😄

pionxzh commented 10 months ago

Can you try to call .video() first and see if recommendedVideos works after that. Note: you need to use the same instance. I think the default cookie set is no longer valid in some regions (EU).

iced-queen commented 10 months ago

Can you try to call .video() first and see if recommendedVideos works after that. Note: you need to use the same instance. I think the default cookie set is no longer valid in some regions (EU).

That still doesn't work. Using the same instance. My server is located in Ireland so that's where the calls are coming from (I guess)

iced-queen commented 10 months ago

Only videoList support country, recommendedVideos page don't even have options for you to choose country 😄

Ohh, it's the Hottest section that does. Is there a function for this already or?

pionxzh commented 10 months ago

Ohh, it's the Hottest section that does. Is there a function for this already or?

const result = await pornhub.videoList({
    order: 'Hottest',
    country: 'Ireland',
})
iced-queen commented 10 months ago

Ohh, it's the Hottest section that does. Is there a function for this already or?

const result = await pornhub.videoList({
    order: 'Hottest',
    country: 'Ireland',
})

Can the country value just be a country code, such as "uk", or does it have to be the country name? Also does this support Top Rated and Most Viewed as well?

pionxzh commented 10 months ago

Can the country value just be a country code, such as "uk", or does it have to be the country name?

Check this Country interce "key", it's the same country list extracted out from PH.

https://github.com/pionxzh/Pornhub.js/blob/a6506b4506788593c05837fc8f8d7a3593b9b854/src/types/Country.ts#L1-L44

country only valid when you choose order = Hottest

iced-queen commented 10 months ago

Can the country value just be a country code, such as "uk", or does it have to be the country name?

Check this Country interce "key", it's the same country list extracted out from PH.

https://github.com/pionxzh/Pornhub.js/blob/a6506b4506788593c05837fc8f8d7a3593b9b854/src/types/Country.ts#L1-L44

So is that a "Yes" or? 😅 Like can it take both the "Key" and the "Value" or do I HAVE to pass the "Key" strings?

pionxzh commented 10 months ago

Only "key", for example, Argentina and Australia. uk is not allowed.

pionxzh commented 10 months ago

Back to the issue, I will need to know what page you were seeing when you got the empty result. I guess it might be the age restriction page... But not sure how to give you a way to provide that information. Let me try VPN tmr.

iced-queen commented 10 months ago

Back to the issue, I will need to know what page you were seeing when you got the empty result. I guess it might be the age restriction page... But not sure how to give you a way to provide that information. Let me try VPN tmr.

I mean, the other functions work. I'm able to search for videos and get information about the video afterwards, just not recommendedVideo()

iced-queen commented 10 months ago

Also a little side-note, on PH's site, the random video url seems to be BASE_URL/video/random and just not BASE_URL/random. Both seem to work, but that could be what's causing it to fail from time to time. I just resolve that issue with:

while (res.id === 'https://www.pornhub.com/') {
    res = await pornhub.randomVideo()
}

But would be better if it never happened, right? 😄

pionxzh commented 10 months ago

nice finding, it will check tonight.

pionxzh commented 10 months ago

PH is down... but ye seems both url can go to the random page. I will update it to /video/random in the next version.

pionxzh commented 10 months ago

OK. I might found the root cause. PH has a JS Protection gate to stop crawler and downloader. They won't accept your requests unless you have a correct RNKEY cookie if your IP has made too many requests.

reference: https://github.com/ytdl-org/youtube-dl/issues/5930

Actions:

pionxzh commented 10 months ago

I might be wrong because you can access other pages without a problem, idk 😄

iced-queen commented 10 months ago

I might be wrong because you can access other pages without a problem, idk 😄

Yeah, it's just the recommended page. Bit weird. Although do you think it'd be possible to make a download feature to download videos?

pionxzh commented 10 months ago

no, but you can try to download from the m3u8 link. See https://github.com/pionxzh/Pornhub.js/issues/90

iced-queen commented 10 months ago

Do you have an update on this issue? 🙂

pionxzh commented 10 months ago

I was so busy this week :(

pionxzh commented 10 months ago

Check https://github.com/pionxzh/Pornhub.js/pull/97 and try dump the page to see what's wrong.

iced-queen commented 10 months ago

Check #97 and try dump the page to see what's wrong.

A little confused what you want me to do? 😄

pionxzh commented 10 months ago

My bad. Can you try to start the application with this constructor? You shall see all the page responses in _dump folder.

const pornhub = new PornHub({ dumpPage: false });
iced-queen commented 10 months ago

My bad. Can you try to start the application with this constructor? You shall see all the page responses in _dump folder.

const pornhub = new PornHub({ dumpPage: false });

Hey again, Sorry for the long wait, I actually forgot about all of this...

After updating and adding that, I don't see a _dump folder? But I do still get the empty result.

iced-queen commented 10 months ago

Update, changed false to true and got a _dump folder now. 1700218744596__recommended.zip

pionxzh commented 10 months ago

lol my bad. should be true.

const pornhub = new PornHub({ dumpPage: true });
iced-queen commented 10 months ago

lol my bad. should be true.

const pornhub = new PornHub({ dumpPage: true });

Yeah I figured 😄 Sent the result above

pionxzh commented 10 months ago

Based on the response, you actually received an empty recommendation list... Then this should be related to pornhub's robot detection. I have no way to fix the issue based on these limited information.

pionxzh commented 10 months ago

You can try VPN or ip pool to get around it.