GithubHelp home page GithubHelp logo

sskender / pornhub-api Goto Github PK

View Code? Open in Web Editor NEW
378.0 31.0 90.0 40 KB

Unofficial API for PornHub.com in Python

License: MIT License

Python 100.00%
pornhub pornhub-api python api proxy parser beautifulsoup beautifulsoup4 pornography pornhub-downloader

pornhub-api's Introduction

PornHub Unofficial API

Unofficial API for pornhub.com in Python

Pull requests are welcome!!!

I find it quite difficult to make time for an active development on this project, so I will be more than happy to merge your pull requests. Thank you all for supporting this project!

Install

pip3 install pornhubapi

How to use

Create client

import pornhub
client = pornhub.PornHub()

Create client with proxy

import pornhub
# With proxy, given a Proxy IP and Port. For the countries with restricted access like Turkey, etc.
client = pornhub.PornHub("5.135.164.72", 3128)

Grab stars

The request can be sorted by: view, trend, subs, alpha, videos, random

for star in client.getStars(10, sort_by="view"):
    print(star)
    print(star["name"])

Create client with search keywords

keywords = ["word1", "word2"]
client = pornhub.PornHub(keywords)

# if using a proxy
client = pornhub.PornHub(keywords, "5.135.164.72", 3128)
# or
client = pornhub.PornHub(ProxyIP="5.135.164.72", ProxyPort=3128, keywords=["word1", "word2"])

for video in client.getVideos(10, page=2):
    print(video)
    print(video["url"])

Sort Video by parameter

When keywords are set: view, rate, long, recent

keywords = ["word1", "word2"]
client = pornhub.PornHub(keywords)

for video in client.getVideos(10, page=2, sort_by="long"):
    print(video)
    print(video["url"])

When keywords are not set: view, rate, long, new, hot

client = pornhub.PornHub()

for video in client.getVideos(10, page=2, sort_by="hot"):
    print(video)
    print(video["url"])

Take full information about all videos

Parameter full_data allows you to get complete information about the video, but its much more slower due to every page needs to be opened

keywords = ["word1", "word2"]
client = pornhub.PornHub(keywords)

for video in client.getVideos(10, page=2, full_data=True):
  print(video)
  print(video["upload_date"])

Get more information about the single video

Method getVideo(url, viewkey) gives more detail information about a single video

client = pornhub.PornHub()

# You can input the full video url, like that
video = client.getVideo("https://www.pornhub.com/view_video.php?viewkey=SOMEKEY")
# Or that
video = client.getVideo(url="https://www.pornhub.com/view_video.php?viewkey=SOMEKEY")
# Or input only viewkey, like that
video = client.getVideo(viewkey="SOMEKEY")

print(video)
print(video["title"])

The method return a dictionary with keywords:

  1. title (type: string) - Video title
  2. views (type: string) - Rounded number of views, for example "2M"
  3. accurate_views (type: integer) - Full number of views, for example "123456789". When video don't have many views views=accurate_views
  4. rating (type: integer) - Video rating in percent
  5. duration (type: string) - Video duration in format "hh:mm:ss"
  6. loaded (type: string) - When the video was uploaded, for example "2 months ago"
  7. upload_date (type: string) - Video upload date in format "yyyy-mm-dd"
  8. likes (type: string) - Similar like views
  9. accurate_likes (type: integer) - Similar like accurate_views
  10. dislikes (type: string) - Similar like views
  11. accurate_dislikes (type: integer) - Similar like accurate_views
  12. favorite (type: string) - How many times added to favorites, rounded. For example "2K"
  13. author (type: string) - Video author (channel)
  14. pornstars (type: list) - Video stars
  15. categories (type: list) - Video categories
  16. tags (type: list) - Video tags
  17. production (type: string) - Video production (Professional or Homemade)
  18. url (type: string) - URL to Video
  19. img_url (type: string) - URL to Preview Image of Video
  20. embed_url (type: string) - URL to Video Player

If the video is not available in your country, in title will "Video not available in your country", in others keys will None

Contributors


SashaSZ


Ibrahim Ipek


Kittinan


Елизаров Роман Русланович


IThinkImOKAY

License

MIT license

pornhub-api's People

Contributors

formerlychucks avatar kittinan avatar notabene01 avatar sashasz avatar sskender avatar yeung-ming 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  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

pornhub-api's Issues

getVideo() giving "***Video not available in your country***" despite IP not being in a restricted region

Seems like there is an error on line 172 of videos.py:
script_data = self._scrapScriptInfo(soup_data.find("script", type="application/ld+json").text)

the return of soup_data.find("script", type="application/ld+json").text is an empty string

Furthermore, this error seems to happen inside the _scrapScriptInfo() method on line 135, where json.loads() method raise the following:
Expecting value: line 1 column 1 (char 0)

Comments

Hi,

Is it possible to extend the code to also retrieve comments under the videos?

Thanks

getPhotos doesn't work, requests.exceptions.ConnectionError

This is my code

client = pornhub.Pornhub(keyword="Lana")

for photo in cluent.getPhotos(5):
    print(photo)

It doesn't work nothing print and after 2 minuts it says requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) . Why?

Full Error here :

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pornstar.py", line 17, in <module>
    for photo_url in client.getPhotos(5):
  File "/home/sofia/.local/lib/python3.8/site-packages/pornhub/photos.py", line 94, in getPhotos
    for album_url in self._scrapAlbumsURL(self._loadAlbumsPage(page)):
  File "/home/sofia/.local/lib/python3.8/site-packages/pornhub/photos.py", line 35, in _loadAlbumsPage
    r = requests.get(search_url, params=payload, headers=HEADERS, proxies=self.ProxyDictionary)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 668, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 668, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 239, in resolve_redirects
    resp = self.send(
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

getVideo method seems absent

getVideo(url, viewkey) which takes in an video url (or keyword) and returns the info of the video seems absent (undefined) in the module

How Photos class work?

Hello, i need this library for my work on GAN's. I need a data set of photos, their ratings and so on. But i couldn't figure out how this class works. Some help would be good.

GetVideos Module Has an Error

File: Videos.py
Function: _scrapVideiosInfo(self,div_el)

The divs attribute has be changed.The images Tag was rename to "data-mediuthumb".

I change there code on my local Computer. Now I want to merge into origin code.
微信图片_20231214112444
微信图片_20231214112449
微信图片_20231214112524

Expecting value: line 1 column 1 (char 0) when calling getVideo() print(video['accurate_views'])

Seems like the problem is this line:
script_data = self._scrapScriptInfo(soup_data.find("script", type="application/ld+json").text)
which yields an empty string.
Why is script_dict = json.loads(soup_data.replace("'",'"')) needed anyway? What is replacing " by'used for for?

Possible fix would be to use script_dict = json.loads(script.contents[0]) if the replace function isn´t actually needed.

GetVideos Module Has an Error

File: Videos.py
Function: _scrapVideiosInfo(self,div_el)

The divs attribute has be changed.The images Tag was rename to "data-mediuthumb".

I change there code on my local Computer. Now I want to merg
微信图片_20231214112444
e into origin code.
微信图片_20231214112524

微信图片_20231214112449

getStars

So I was wondering, I read through the stars class and saw that the first stars would be : # get div with list of stars (month popular is the 1st).
Right now I'm trying and I get Mia Khalifia in return and she isn't the first. Why?

demo code error (pip installing the wrong version)

When initializing the client with search keywords, demo code says:
keywords = ["word1", "word2"]
client = pornhub.PornHub(keywords)

But given the params of Pornhub is init(self, ProxyIP=None, ProxyPort=None, keywords=[], *args), the demo code actually assigns keywords to the ProxyIP, which took me some time to troubleshoot this minor error.

Correct demo code should be:
keywords = ["word1", "word2"]
client = pornhub.PornHub(keywords=keywords)

, where the input is assign to the keywords param

getVideos attribute don't work?

I have been toying around with it a lot today, but it seems that the getVideos attribute don't work.

`keywords_table = ["teen", "teens", "boobs","amateur", "asian", "blonde", "milf", "step", "lesbian", "threesome", "creampie", "tits" ]
keywords = random.sample(keywords_table, 2)
client = pornhub.PornHub(keywords)

print(keywords)

video_page = random.randint(1,50)

#print(video_page)
for video in client.getVideos(1,video_page,False):
print(video["url"])
`
I get the same result everytime no watter the keywords and the page number.

This is not working when I try to obtain stars or even search a video through keywords

`
Traceback (most recent call last):
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in validate_conn
conn.connect()
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/util/ssl
.py", line 428, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/util/ssl
.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in validate_conn
conn.connect()
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/connection.py", line 411, in connect
self.sock = ssl_wrap_socket(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/util/ssl
.py", line 428, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/urllib3/util/ssl
.py", line 472, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "api_test.py", line 4, in
for star in client.getStars(10):
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/pornhub/stars.py", line 80, in getStars
for possible_star in self._scrapLiStars(self._loadStarsPage(page)):
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/pornhub/stars.py", line 12, in _loadStarsPage
r = requests.get(BASE_URL + PORNSTARS_URL, params=payload, headers=HEADERS, proxies=self.ProxyDictionary)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/suraj/miniconda3/envs/python3.8_env/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))`
Getting this error.....What can be done to resolve the issue ?

Endless video download

My code:

import pornhub
client = pornhub.PornHub()

for video in client.getVideos(10, page=2):
    print(video)
    print(video["url"])

If you stop the code, you get this error
UntitlErrored

Make package install-able with pip

If possible, could you make this package install-able with pip? Would be great as this currently does not have a setup.py file and is causing issues with larger programs where this package would be placed in a requirements.txt file.

Thank you so much if you could!

Can't we use sort_by parameter

We can search but can we use sort_by="mostviewd" or sort_by="newest" parameter ?
Currently it's using the default parameter right ?

[Error Page Not Found] occurs when search keys' length in utf-8 bytes exceeds 100 (>= 100)

While using the code, an error raised in Videos._scrapLiVideos(*) showing that no LiVideo is Found, this is because the keywords I used had a combined length in bytes (utf-8) >= 100, which cause the website to raise an [Error Page Not Found]

The following code is used to measure length of my keywords (could be in different languages) (where s is the one string concatenated from all keywords by whitespace):

s = ' '.join(self.keywords)
def utf8len(s):
    return len(s.encode('utf-8'))

It seems to me that the keywords join together (including whitespace) needs to have an utf-8 length strictly smaller than 100 (utf8len<100)

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.