pionxzh / Pornhub.js

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

`searchVideo` got empty result #73

Closed iced-queen closed 1 year ago

iced-queen commented 1 year ago

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?

pionxzh commented 1 year ago

Seems this is the same issue as #71, and it works on my side. I suspect you got a different DOM because of IP (Europe?) or AB Testing.

Can you paste the HTML you get on the search page here or send it to my email? So that I can analyze it.

iced-queen commented 1 year ago

Seems this is the same issue as #71, and it works on my side. I suspect you got a different DOM because of IP (Europe?) or AB Testing.

Can you paste the HTML you get on the search page here or send it to my email? So that I can analyze it.

What do you mean the HTML I get?

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

Is all it returns. :)

iced-queen commented 1 year ago

Oh, do you mean you want me to go to https://www.pornhub.com/ and send you the HTML in "inspect"?

iced-queen commented 1 year ago

If so; pornhub.zip

pionxzh commented 1 year ago

@chocobearxo I need this view-source:https://www.pornhub.com/video/search?search=ass

iced-queen commented 1 year ago

view-source_https___www.pornhub.com_video_search_search=ass.zip

pionxzh commented 1 year ago

I suspect your ph instance got a shadow ban or something. The HTML you gave me is correct. But I think the content you get when you call .searchVideo might be empty or some warning text.

iced-queen commented 1 year ago

I suspect your ph instance got a shadow ban or something. The HTML you gave me is correct. But I think the content you get when you call .searchVideo might be empty or some warning text.

So? 😅 Is it an issue in the library or?

pionxzh commented 1 year ago

I'm still figuring out what it can be. I will improve the logging and error detection in the library so that you can monitor what happened.

pionxzh commented 1 year ago

So it worked before, but not anymore recently? What is the current status?

DummyYummy commented 1 year ago

Guys, maybe I don't understand something, but you just ignore cookies inside buildRequest function. In the end request is always send with empty headers. I just had a problem that all requests return empty results because of age verification.

    buildRequest<U extends Record<string, any>, T>(method: 'get' | 'post' | 'post-form', url: string, data?: U): Promise<T> {
        const headers: HeadersInit = {}
        const opts: RequestInit = { method, headers }

        if (method === 'post') {
            headers['Content-Type'] = 'application/json'
            opts.body = JSON.stringify(data)
        }

        if (method === 'post-form') {
            // headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
            opts.method = 'post'
            if (data) opts.body = this.buildParams<U>(data)
        }

        return this.fetch(url, opts)
            .then(res => this.toJson(res) as T)
            .catch(err => Promise.reject(err))
    }

As soon as I added locally smth like this:

const headers = { cookie: Object.entries(this.getCookies()).map(pair =>${pair[0]}=${pair[1]}).join('; ')};

Everything started to work fine

pionxzh commented 1 year ago

Man 😭 You are right. I can't believe this has been wrong for so long.

pionxzh commented 1 year ago

This request module is like shit 😅 I will reimplement it sometime.

pionxzh commented 1 year ago

@DummyYummy @chocobearxo v1.7.1 released. Let me know if it works.

iced-queen commented 1 year ago

@DummyYummy @chocobearxo v1.7.1 released. Let me know if it works.

Seems like searchVideo() works, but video() still throws an error that I mentioned in #80

pionxzh commented 1 year ago

@chocobearxo Can you verify this with 1.7.4?

iced-queen commented 1 year ago

@chocobearxo Can you verify this with 1.7.4?

Well I've tested it a lot now and the only function that still seems to have issues is randomVideo() but like stated in another issue regarding that, that's an issue on Pornhub's end, not the library, so in short; yeah I pretty much think 1.7.4 fixed the issues. 😄

For others, this can be easily fixed with a while loop if you wanna use that.

let res = await pornhub.randomVideo()

while (res.id === 'https://www.pornhub.com/') {
    res = await pornhub.randomVideo()
}
// Continue whatever you're doing
iced-queen commented 1 year ago

So now you can easily focus on the other issues/suggestions whenever you've got time for that. 😊