Using Videos

Video objects are emitted by:

  • Client.get() when searching for a specific video

  • Query when 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:

PHUB Video Properties

Property

Type

Description

video.title

str

Video title. Might depend on client language.

video.image

Image

The video thumbnail.

video.is_vertical

bool

Whether the video is in vertical (phone) mode.

video.orientation

str

The sexual orientation of the video (straight, gay, etc.).

video.duration

datetime.timedelta

The length of the video.

video.tags

list[.Tag]

List of video tags.

video.like

int

Likes amount of the video.

video.views

int

Number of views of the video.

video.hotspots

list[int]

Timestamps of the video hotspots. Used by Pornhub player to display hot moments.

video.date

datetime.datetime

The video publication date.

video.pornstars

User

Pornstars in the video, represented as a list of User objects.

video.categories

list[str]

The video categories.

video.author

User

The user account that posted the video.

video.id

int

The video ID, used internally by Pornhub. Not to be confused with the video viewkey.

video.watched

bool

Whether the video has been watched by the client (will not work in some cases).

video.is_free_premium

bool

Whether the video is part of Pornhub free premium plan (will not work in some cases).

video.preview

Image

The small preview you see when hovering a video (will not work in some cases).

video.is_favorite

bool

Whether the video is set a favorite by the client.

video.is_HD

bool

Whether the video is available in a High Definition quality.

video.is_VR

bool

Whether the video is available in VR.

video.embed

str

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:

PHUB Video Interactions

Method

Description

Video.like()

Set or unset the video as liked.

Video.favorite()

Set or unset the video as favorite.

Video.watch_later()

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()