EchterAlsFake / PHUB

A lightweight API for Pornhub
https://phub.rtfd.io
GNU General Public License v3.0
67 stars 22 forks source link

TypeError: 'HTMLQuery' object is not subscriptable #36

Closed EchterAlsFake closed 8 months ago

EchterAlsFake commented 8 months ago

Hi,

I am trying to use the search generator and iterate only until specific videos.

Here's an example:

c = Client(language="en")
search = c.search("Mia Khalifa", feature=HTMLQuery)

for video in search[0:10]:
    print(video.title)

I tried it with the HTMLQuery and with the JSONQuery

With both queries I got the TypeError.

(I know you have currently limited ability, so no rush about it :)

Egsagon commented 8 months ago

Hi, in the last updates i made to the master branch, i (temporarly) removed query iteration control with indexes and slices.

The reason for that was that some queries concerning user accounts would eventually raise errors or ignore certain videos. This breaks the whole query index system, which is why i replaced it with a simpler iterator. I remember adding a filter method that would allow you to filter iterated videos, including a maximum generator length. I haven't pushed this commit yet because as i said i temporarly stopped working on this project. I'd also like to have only one query for each pornhub object (one for users, one for videos, etc.) to make things cleaner.

I obviously do not make pornhub APIs for a living, so I'm still unsure of how i want the query system to be like because of all these constraints. Until i get back to it, you might want to use an older version from pypi or the releases tab.

Egsagon commented 8 months ago

Working on this again, you can now do:

for video in query.sample(max = 10): ...

You can also use the sample method to filter specific videos:

# Iterate only videos with more than 10k views
for video in query.sample(filter = lambda v: v.views > 10_000): ...

You can also directly iterate pages for more control:

for video in query.pages: ...

I'm not pushing this to master yet because there still are bugs with user videos/uploads queries (#27). It's on the dev branch.

I know this does not quite give the same comfort than slices, i'll try to add more arguments to the sample method (like an approximation of a start index, or a starting page index).