Git Product home page Git Product logo

pornhub-api's Introduction

Unofficial api for pornhub.com

image

image

image

Key Features

  • response are fully-annotated with pydantic
  • rest without parsing

Installing

$ pip install pornhub-api

or with aiohttp support

$ pip install pornhub-api[aiohttp-backend]

or with httpx support

$ pip install pornhub-api[httpx-backend]

Supported versions

  • Python 3.7+

Getting started

Initiate Api client

from pornhub_api import PornhubApi

api = PornhubApi()

Initiate with AioHttp backend

import asyncio
from pornhub_api.backends.aiohttp import AioHttpBackend


async def execute():
    async with AioHttpBackend() as backend:
        api = PornhubApi(backend=backend)
        video = await api.video.get_by_id("ph560b93077ddae")
        print(video.title)

asyncio.run(execute())

Search Videos

videos = api.search_videos.search_videos(
    "chechick",
    ordering="mostviewed",
    period="weekly",
    tags=["black"],
)
for vid in videos:
    print(vid.title, vid.video_id)

Get Stars

api.stars.all()
or
api.stats.all_detailed()

Get single Video details

video = api.video.get_by_id("ph560b93077ddae")
print(video.title)

Get all videos tags or categories

categories = api.video.categories()
tags = api.video.tags("a")

Check Video availability

response = api.video.is_active("ph560b93077ddae")
print(response.is_active)

Search video by random tag and category

import random
api = PornhubApi()

tags = random.sample(api.video.tags("f").tags, 5)
category = random.choice(api.video.categories().categories)
result = api.search.search_videos(ordering="mostviewed", tags=tags, category=category)

print(result.size())
for vid in result:
    print(vid.title, vid.url)

pornhub-api's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar derfirm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pornhub-api's Issues

Example with page search

I have this in my code.

data = api.search.search(
text,thumbsize="small",page=3)

I always get the same result by changing the page.

What am I doing wrong?

Return uploader?

Hey, I'm using this API mainly to grab metadata, but there doesn't seem to be a way to grab the name of the account that uploaded said video. Could something like that be implemented? Or maybe it already exists and I'm just blind.
Regardless, it's something that I think would be very useful to pull. Thanks

decoder error

What about with this error

Traceback (most recent call last):
File "ph.py", line 7, in
tags = random.sample(api.video.tags("f").tags, 5)
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pornhub_api/modules/video.py", line 45, in tags
return self.backend.send_request(
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/pornhub_api/backends/requests.py", line 12, in send_request
data = response.json()
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/data/data/com.termux/files/usr/lib/python3.8/json/init.py", line 357, in loads
return _default_decoder.decode(s)
File "/data/data/com.termux/files/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/data/data/com.termux/files/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

View a video

Hi.
I would like to make a script that views a video and makes the viewer counter increment.
Any ideas on how making it?
Maybe i should just GET the page with the video, and then download it?
Thank you in advance

Attributeerror

Hello, seems like the libary do not have api.stats.all() and api.stats.all_detailed() however this is included in the read.me
I wanted t print out the stats so i used following code:

print(api.stats.all_detailed())

After running the code i got this issue:

Traceback (most recent call last):
  File "D:\my_python_projects\pornhub_discordbot\bot.py", line 20, in <module>
    print(api.stats.all_detailed())
AttributeError: 'PornhubApi' object has no attribute 'stats'

The same Traceback happen when using print(api.stats.all())
Hopefully you could help me there

premium

Hey! Is it possible to parse premium video? I have a premium account from pornhub.

Playlist support

Would be really cool if there was playlist support, e.g. ability to see the video ids for all the videos in a playlist given the playlist id

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.