Using Videos¶
Video objects are emitted by:
Client.get()when searching for a specific videoQuerywhen enumerating for videos in a query
Once initialised, a Video object does not do anything.
It manages requests and caches automatically to be as fast as possible.
You can use the following properties on a video:
Property |
Type |
Description |
|---|---|---|
|
Video title. Might depend on client language. |
|
|
The video thumbnail. |
|
|
Whether the video is in vertical (phone) mode. |
|
|
The sexual orientation of the video (straight, gay, etc.). |
|
|
The length of the video. |
|
|
|
List of video tags. |
|
Likes amount of the video. |
|
|
Number of views of the video. |
|
|
|
Timestamps of the video hotspots. Used by Pornhub player to display hot moments. |
|
The video publication date. |
|
|
Pornstars in the video, represented as a list of |
|
|
|
The video categories. |
|
The user account that posted the video. |
|
|
The video ID, used internally by Pornhub. Not to be confused with the video viewkey. |
|
|
Whether the video has been watched by the client (will not work in some cases). |
|
|
Whether the video is part of Pornhub free premium plan (will not work in some cases). |
|
|
The small preview you see when hovering a video (will not work in some cases). |
|
|
Whether the video is set a favorite by the client. |
|
|
Whether the video is available in a High Definition quality. |
|
|
Whether the video is available in VR. |
|
|
The video embed URL, if you want to integrate it into a website. |
Warning
Some video properties (preview, watched and is_free_premium) are only available
if the video comes from a VideoQuery because of the limited visibility of
the data. You can use these properties by using Query.sample() and directly on the
video object, although it is not recommended.
for video in query.sample(watched = True):
print(video.title)
# Is the same as
for video in query.sample():
if video.watched:
print(video.title)
If you absolutely need to access these properties outside of a query, you can turn on query emulation with video.ALLOW_QUERY_SIMULATION = True. This will create a fake query but is very slow and requires user authentication.
Interactions¶
As of version 4.3, some interactions are available with the video:
Method |
Description |
|---|---|
Set or unset the video as liked. |
|
Set or unset the video as favorite. |
|
Add or remove the video from the watch later playlist. |
Refreshing data¶
Refreshing Video objects is done through the Video.refresh() method.
# Watch the video counter
import time
import phub
client = phub.Client()
video = client.get(...)
while 1:
print(f'The video has {video.like.up} likes!')
time.sleep(60 * 10) # Every 10 min
video.refresh()