Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with the randomVideo function #68

Closed
iced-queen opened this issue Jul 13, 2023 · 19 comments
Closed

Issue with the randomVideo function #68

iced-queen opened this issue Jul 13, 2023 · 19 comments
Labels
bug Something isn't working

Comments

@iced-queen
Copy link

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

@iced-queen
Copy link
Author

Just go the issue where it'd return the homepage again.
The output looks like this:

{
  id: 'https://www.pornhub.com/',
  title: 'Free Porn Videos & Sex Movies - Porno, XXX, Porn Tube | Pornhub',
  views: 0,
  vote: { up: 0, down: 0, total: 0, rating: NaN },
  premium: false,
  thumb: '',
  videos: [],
  provider: null,
  tags: [],
  pornstars: [],
  categories: [],
  duration: 0,
  durationFormatted: '00:00'
}

@pionxzh
Copy link
Owner

pionxzh commented Jul 13, 2023

Thanks for reporting. I will look into it.

@pionxzh pionxzh added the bug Something isn't working label Jul 13, 2023
@pionxzh
Copy link
Owner

pionxzh commented Jul 13, 2023

Btw, I think there is something blocking us to get the correct content. Our CI testing sometimes will fail for unknown reasons.

@pionxzh
Copy link
Owner

pionxzh commented Jul 13, 2023

  1. The missing preview: I didn't notice that we can get preview from the video page. This will be added as an enhancement. 👍
  2. The mismatched views: This is a historical issue. When I created this library, Pornhub still provided detailed views on the video page. So I choose to parse the string. But why not parse the views on the search page? My bad 🤣
    I'm thinking about providing two new fields for parsed/original strings.

@pionxzh
Copy link
Owner

pionxzh commented Jul 13, 2023

For the issue of getting homepage from randomVideo(), I have no idea :(
Let me know if you found any pattern. 🙏

@iced-queen
Copy link
Author

For the issue of getting homepage from randomVideo(), I have no idea :( Let me know if you found any pattern. 🙏

It seems to be a bug on PH's end. I just tried the /random endpoint multiple times and it directed me to the homepage sometimes. I guess a workaround for this would be with a while loop? And have it repeat the process if <result>.id is equal to https://www.pornhub.com/.

@iced-queen
Copy link
Author

Also I just tried:

let res = await pornhub.randomVideo()
if (res.id === 'https://www.pornhub.com/') return;
console.log(res)
let info = await pornhub.video(res.id)
console.log(info)
return

Those two returns the exact same and neither has a preview.

{
  id: 'ph61e099ebaefbe',
  title: '18 yr old gets backshots ',
  views: 0,
  vote: { up: 0, down: 0, total: 0, rating: NaN },
  premium: false,
  thumb: '',
  videos: [],
  provider: null,
  tags: [
    'ebony',
    'girl-loses-virginity',
    'ebony-backshots',
    'homemade',
    'real-couple-homemade',
    'amateur-college',
    'anal'
  ],
  pornstars: [],
  categories: [
    '60FPS',
    'Amateur',
    'College-(18+)',
    'Ebony',
    'Female-Orgasm',
    'Reality',
    'Small-Tits',
    'Teen-(18+)',
    'Verified-Amateurs'
  ],
  duration: 12,
  durationFormatted: '00:12'
}
{
  id: 'ph61e099ebaefbe',
  title: '18 yr old gets backshots ',
  views: 0,
  vote: { up: 0, down: 0, total: 0, rating: NaN },
  premium: false,
  thumb: '',
  videos: [],
  provider: null,
  tags: [
    'ebony',
    'girl-loses-virginity',
    'ebony-backshots',
    'homemade',
    'real-couple-homemade',
    'amateur-college',
    'anal'
  ],
  pornstars: [],
  categories: [
    '60FPS',
    'Amateur',
    'College-(18+)',
    'Ebony',
    'Female-Orgasm',
    'Reality',
    'Small-Tits',
    'Teen-(18+)',
    'Verified-Amateurs'
  ],
  duration: 12,
  durationFormatted: '00:12'
}

views and vote are both incorrect. provider is also null.

Plus the searchVideo() function returns the actual URL (<result>.url) which I liked. It's kinda annoying having to do

let url = 'https://www.pornhub.com/view_video.php?viewkey=' + res.id

with some of the functions :D

@pionxzh
Copy link
Owner

pionxzh commented Jul 20, 2023

  1. Now both searchVideo() and video() will respond with id and url. You don't need to concat the URL manually anymore.
  2. preview is provided in video(), but the size is actually bigger than the one you get in search.
  3. I noticed the NaN on rating from the output you pasted. Fixed 😄

@pionxzh
Copy link
Owner

pionxzh commented Jul 20, 2023

For the issue of empty views and votes, this is the output I get from ph61e099ebaefbe. I suspect there is a regional difference in the DOM structure. Btw, you can notice that there is a small diff on title.

{
  id: 'ph61e099ebaefbe',
  url: 'https://www.pornhub.com/view_video.php?viewkey=ph61e099ebaefbe',
  title: '18 Yr old Gets Backshots',
  views: 3000,
  vote: { up: 8, down: 1, total: 9, rating: 0.89 },
  premium: false,
  thumb: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  preview: 'https://di.phncdn.com/videos/202201/13/401270691/original/(m=eaAaGwObaaamqv)(mh=u1n8G4v4Uj8UTXSs)7.jpg',
  videos: [],
  categories: [
    '60FPS',
    'Amateur',
    'College-(18+)',
    'Ebony',
    'Female-Orgasm',
    'Reality',
    'Small-Tits',
    'Teen-(18+)',
    'Verified-Amateurs'
  ],
  duration: 12,
  durationFormatted: '00:12'
}

@pionxzh
Copy link
Owner

pionxzh commented Jul 20, 2023

And for the redirection strategy, I would say handling this in the library is not ideal. Maybe we should detect this kind of URL mismatch and throw a Custom Error?

@pionxzh
Copy link
Owner

pionxzh commented Jul 20, 2023

released in v1.6.0

@pionxzh
Copy link
Owner

pionxzh commented Jul 27, 2023

Hi @chocobearxo , do you 100% see the empty views and vote? If so, please provide me the HTML of the video page.

@pionxzh
Copy link
Owner

pionxzh commented Jul 27, 2023

Dude, this random video is so unstable. I got like 2/5 chances to get the main page. 🤣

@iced-queen
Copy link
Author

Hi @chocobearxo , do you 100% see the empty views and vote? If so, please provide me the HTML of the video page.

Sorry can you update me a bit where we're at? 😂

Dude, this random video is so unstable. I got like 2/5 chances to get the main page. 🤣

Yes!

@pionxzh
Copy link
Owner

pionxzh commented Jul 28, 2023

Sorry can you update me a bit where we're at? 😂

This issue contains many minor items, and most of them have been fixed.
I have moved the views formatting issue to #78
Now empty views is the last thing we need to focus on.
But the problem is I don't know what HTML you actually get in the library.

@iced-queen
Copy link
Author

This has been fixed, haven't it?

@pionxzh
Copy link
Owner

pionxzh commented Aug 28, 2023

I don't know, did you still get 0 views with video("ph61e099ebaefbe") ?

@iced-queen
Copy link
Author

I don't know, did you still get 0 views with video("ph61e099ebaefbe") ?

I just tried to log the result from video() and it returned:

{
  id: 'ph61b09f51588ec',
  url: 'https://www.pornhub.com/view_video.php?viewkey=ph61b09f51588ec',
  title: 'Big Ass Latina is Fucked by her Stepbrother after the Gym. she Rides him and Takes all the Cum',
  views: 7800000,
  vote: { up: 20000, down: 3000, total: 23000, rating: 0.87 },
  premium: false,
  thumb: 'https://ei.phncdn.com/videos/202112/08/399331681/original/(m=eaf8Ggaaaa)(mh=x3pHVpB3KOGFFwpr)8.jpg',
  preview: 'https://ei.phncdn.com/videos/202112/08/399331681/original/(m=eaAaGwObaaaa)(mh=vHcc0xLJsGnbrhm3)8.jpg',
  videos: [],
  provider: { username: 'lunaalessandra', url: '/model/lunaalessandra' },
  tags: [
    'step-brother',     'big-ass',
    'big-tits',         'ebony',
    'cum-on-tits',      'hot-latin',
    'hot-step-sister',  'real-amateur',
    'sloppy-blowjob',   'sex-after-gym',
    'riding-dick',      'doggystyle-pov',
    'horny-stepsister', 'big-boobes-babe',
    'tight-pussy',      'sexo-duro'
  ],
  pornstars: [],
  categories: [
    'Big-Ass',
    'Big-Tits',
    'Blowjob',
    'Exclusive',
    'HD-Porn',
    'Hardcore',
    'Latina',
    'POV',
    'Step-Fantasy',
    'Verified-Amateurs',
    'Verified-Couples'
  ],
  duration: 1568,
  durationFormatted: '26:08',
  uploadDate: 2021-12-08T14:08:21.000Z
}

So I'd assume it's fixed, yes. :)

By the way a reminder that you'd add formatted views (#78) 😄

@pionxzh
Copy link
Owner

pionxzh commented Aug 28, 2023

I know, I know 🛩️

@pionxzh pionxzh closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants