phub 4.7.8__tar.gz → 4.7.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {phub-4.7.8 → phub-4.7.9}/PKG-INFO +1 -1
  2. {phub-4.7.8 → phub-4.7.9}/pyproject.toml +1 -1
  3. {phub-4.7.8 → phub-4.7.9}/src/phub/consts.py +1 -2
  4. {phub-4.7.8 → phub-4.7.9}/src/phub/core.py +4 -3
  5. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/playlist.py +10 -13
  6. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/user.py +19 -5
  7. phub-4.7.9/src/phub/tests/test_auth.py +26 -0
  8. {phub-4.7.8 → phub-4.7.9}/src/phub/tests/test_model.py +8 -3
  9. {phub-4.7.8 → phub-4.7.9}/src/phub/tests/test_playlist.py +5 -2
  10. {phub-4.7.8 → phub-4.7.9}/src/phub/tests/test_search.py +8 -5
  11. {phub-4.7.8 → phub-4.7.9}/src/phub/tests/test_video.py +6 -3
  12. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/PKG-INFO +1 -1
  13. phub-4.7.8/src/phub/tests/test_auth.py +0 -21
  14. {phub-4.7.8 → phub-4.7.9}/LICENSE +0 -0
  15. {phub-4.7.8 → phub-4.7.9}/README.md +0 -0
  16. {phub-4.7.8 → phub-4.7.9}/pypi.md +0 -0
  17. {phub-4.7.8 → phub-4.7.9}/setup.cfg +0 -0
  18. {phub-4.7.8 → phub-4.7.9}/setup.py +0 -0
  19. {phub-4.7.8 → phub-4.7.9}/src/phub/__init__.py +0 -0
  20. {phub-4.7.8 → phub-4.7.9}/src/phub/__main__.py +0 -0
  21. {phub-4.7.8 → phub-4.7.9}/src/phub/errors.py +0 -0
  22. {phub-4.7.8 → phub-4.7.9}/src/phub/literals.py +0 -0
  23. {phub-4.7.8 → phub-4.7.9}/src/phub/modules/__init__.py +0 -0
  24. {phub-4.7.8 → phub-4.7.9}/src/phub/modules/display.py +0 -0
  25. {phub-4.7.8 → phub-4.7.9}/src/phub/modules/parser.py +0 -0
  26. {phub-4.7.8 → phub-4.7.9}/src/phub/modules/rss.py +0 -0
  27. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/__init__.py +0 -0
  28. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/account.py +0 -0
  29. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/data.py +0 -0
  30. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/feed.py +0 -0
  31. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/image.py +0 -0
  32. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/query.py +0 -0
  33. {phub-4.7.8 → phub-4.7.9}/src/phub/objects/video.py +0 -0
  34. {phub-4.7.8 → phub-4.7.9}/src/phub/tests/__init__.py +0 -0
  35. {phub-4.7.8 → phub-4.7.9}/src/phub/utils.py +0 -0
  36. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/SOURCES.txt +0 -0
  37. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/dependency_links.txt +0 -0
  38. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/entry_points.txt +0 -0
  39. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/requires.txt +0 -0
  40. {phub-4.7.8 → phub-4.7.9}/src/phub.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phub
3
- Version: 4.7.8
3
+ Version: 4.7.9
4
4
  Summary: An API for Pornhub
5
5
  Author-email: Egsagon <egsagon.git@gmail.com>, EchterAlsFake <EchterAlsFake@proton.me>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "phub"
3
- version = "4.7.8"
3
+ version = "4.7.9"
4
4
  description = "An API for Pornhub"
5
5
  authors = [
6
6
  {name = 'Egsagon', email = "egsagon.git@gmail.com"},
@@ -227,8 +227,7 @@ class re:
227
227
  container = find( engine.DOTALL, r'class=\"container(.*)' ) # Get the page container
228
228
  document = find( engine.DOTALL, r'.*' ) # Match a whole document
229
229
  get_playlist_unavailable = find( engine.DOTALL, r': (\d+)</h5' ) # Get playlist unavailable videos amount
230
- playlist_data = find( engine.DOTALL, r'id=\"playlistWrapper(.*?)playlistSectionWrapper\"' ) # Get playlist data container
231
- get_playlist_size = find( engine.DOTALL, r'- (\d+).*?\"avatarPosition' ) # Get playlist video amount
230
+ get_playlist_size = find( engine.DOTALL, r'var itemsCount = (.*?) ||' ) # Get playlist video amount
232
231
  get_playlist_likes = find( engine.DOTALL, r'<span class="votesUp">(.*?)</span>' ) # Get playlist likes
233
232
  get_playlist_dislikes = find( engine.DOTALL, r'<span class="votesDown">(.*?)</span>' ) # Get playlist dislikes
234
233
  get_playlist_ratings = find( engine.DOTALL, r'<span class="percent">(.*?)%</span>' ) # Get paylist like/dislike ratio
@@ -1,7 +1,7 @@
1
1
  '''
2
2
  PHUB core module.
3
3
  '''
4
-
4
+ import re
5
5
  import time
6
6
  import logging
7
7
  import random
@@ -209,12 +209,13 @@ class Client:
209
209
  raise errors.ClientAlreadyLogged()
210
210
 
211
211
  # Get token
212
- page = self.call('').text
212
+ page = self.call('https://www.pornhub.com').text
213
213
  try:
214
214
  base_token = consts.re.get_token(page)
215
215
 
216
216
  except errors.RegexError:
217
- raise LoginFailed("(Probably) invalid credentials. If you are sure they are correct, please report this issue.")
217
+ self.logger.warning("Couldn't get token. Trying alternative method...")
218
+ base_token = re.search(r'data-token="(.*?)"', string=page).group(1)
218
219
 
219
220
  # Send credentials
220
221
  payload = consts.LOGIN_PAYLOAD | self.credentials | {'token': base_token}
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import re
4
+ import time
3
5
  from typing import TYPE_CHECKING
4
6
  from functools import cache, cached_property
5
7
 
@@ -34,7 +36,6 @@ class Playlist(queries.VideoQuery):
34
36
 
35
37
  # Initialise
36
38
  super().__init__(client, func = None)
37
-
38
39
  # Define both playlist url (first page) and chunked (next pages)
39
40
  self.url = 'playlist/' + str(pid)
40
41
  self.chunk_url = f'playlist/viewChunked?id={pid}' '&token={token}&page={page}'
@@ -70,13 +71,9 @@ class Playlist(queries.VideoQuery):
70
71
  raise errors.NoResult()
71
72
 
72
73
  return response.text
73
-
74
- @cached_property
75
- def _data(self) -> str:
76
- return consts.re.playlist_data(self._page)
77
74
 
78
75
  def __len__(self) -> int:
79
- return int(consts.re.get_playlist_size(self._page))
76
+ return int(re.search(r'var\s+itemsCount\s*=\s*(\d+)\s*\|\|', string=self._page).group(1))
80
77
 
81
78
  @cached_property
82
79
  def hidden_videos_amount(self) -> int:
@@ -89,27 +86,27 @@ class Playlist(queries.VideoQuery):
89
86
  @cached_property
90
87
  def like(self) -> Like:
91
88
  return Like(
92
- int(consts.re.get_playlist_likes(self._data)),
93
- int(consts.re.get_playlist_dislikes(self._data)),
94
- float(consts.re.get_playlist_ratings(self._data))
89
+ int(consts.re.get_playlist_likes(self._page)),
90
+ int(consts.re.get_playlist_dislikes(self._page)),
91
+ float(consts.re.get_playlist_ratings(self._page))
95
92
  )
96
93
 
97
94
  @cached_property
98
95
  def views(self) -> int:
99
- raw: str = consts.re.get_playlist_views(self._data)
96
+ raw: str = consts.re.get_playlist_views(self._page)
100
97
  return int(raw.replace(',', ''))
101
98
 
102
99
  @cached_property
103
100
  def tags(self) -> list[str]:
104
- return consts.re.get_playlist_tags(self._data)
101
+ return consts.re.get_playlist_tags(self._page)
105
102
 
106
103
  @cached_property
107
104
  def author(self) -> User:
108
- url = consts.re.get_playlist_author(self._data)
105
+ url = consts.re.get_playlist_author(self._page)
109
106
  return User.get(self.client, consts.HOST + url)
110
107
 
111
108
  @cached_property
112
109
  def title(self) -> str:
113
- return consts.re.get_playlist_title(self._data)
110
+ return consts.re.get_playlist_title(self._page)
114
111
 
115
112
  # EOF
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
  import logging
3
+ import re
3
4
 
4
5
  from dataclasses import dataclass
5
6
  from functools import cached_property
7
+
6
8
  from base_api.base import setup_logger
7
9
  from typing import TYPE_CHECKING, Literal, Union
8
10
 
@@ -223,8 +225,16 @@ class User:
223
225
  '''
224
226
  The user bio.
225
227
  '''
226
-
227
- return consts.re.user_bio(self._page, throw = False)
228
+ try:
229
+ bio = consts.re.user_bio(self._page, throw = False)
230
+ assert bio, str
231
+ except (errors.RegexError, AssertionError):
232
+ try:
233
+ bio = re.search(r'<div class="profileReadMoreExcerpt">\s*(.*?)\s*</div>', self._page, re.DOTALL).group(1)
234
+ except AttributeError:
235
+ return None # User has no bio probably
236
+
237
+ return bio
228
238
 
229
239
  @cached_property
230
240
  def info(self) -> dict[str, str]:
@@ -247,10 +257,14 @@ class User:
247
257
  '''
248
258
 
249
259
  from . import Image
250
-
251
- url = (getattr(self, '_cached_avatar_url')
260
+ try:
261
+ url = (getattr(self, '_cached_avatar_url')
252
262
  or consts.re.user_avatar(self._page))
253
-
263
+
264
+ except errors.RegexError:
265
+ url = (getattr(self, '_cached_avatar_url')
266
+ or re.search(r"/(?:model|pornstar)/(.*?)/about", string=self._page).group(1))
267
+
254
268
  return Image(client = self.client,
255
269
  url = url,
256
270
  name = f'{self.name}-avatar')
@@ -0,0 +1,26 @@
1
+ try:
2
+ import os
3
+ from phub import Client
4
+ from base_api.modules.config import config
5
+ from base_api.base import BaseCore
6
+
7
+ except (ModuleNotFoundError, ImportError):
8
+ import os
9
+ from ...phub import Client
10
+ from base_api.modules.config import config
11
+ from base_api.base import BaseCore
12
+
13
+ def test_auth():
14
+
15
+ email = os.getenv('EMAIL')
16
+ password = os.getenv('PASSWORD')
17
+
18
+ assert email and password
19
+
20
+ config.request_delay = 0
21
+ core = BaseCore(config=config)
22
+ client = Client(language="en", core=core, email=email, password=password)
23
+
24
+ assert client.logged
25
+
26
+ # EOF
@@ -1,14 +1,19 @@
1
1
  try:
2
2
  from phub import Client
3
-
3
+ from base_api.modules.config import config
4
+ from base_api.base import BaseCore
4
5
  except (ModuleNotFoundError, ImportError):
5
6
  from ...phub import Client
7
+ from base_api.modules.config import config
8
+ from base_api.base import BaseCore
9
+
10
+ config.request_delay = 0
11
+ core = BaseCore(config=config)
12
+ client = Client(language="en", core=core) # Make a delay, so that PornHub isn't stressed too much
6
13
 
7
14
  url = "https://pornhub.com/pornstar/nancy-a"
8
- client = Client(language="en") # Make a delay, so that PornHub isn't stressed too much
9
15
  model = client.get_user(url)
10
16
 
11
-
12
17
  def test_info():
13
18
  assert isinstance(model.info, dict)
14
19
 
@@ -1,8 +1,11 @@
1
1
  try:
2
2
  from phub import Client, Like, User
3
-
4
- except (ImportError, ModuleNotFoundError):
3
+ from base_api.modules.config import config
4
+ from base_api.base import BaseCore
5
+ except (ModuleNotFoundError, ImportError):
5
6
  from ...phub import Client, Like, User
7
+ from base_api.modules.config import config
8
+ from base_api.base import BaseCore
6
9
 
7
10
  url = "https://de.pornhub.com/playlist/113348141"
8
11
  client = Client(language="en")
@@ -1,13 +1,16 @@
1
1
  try:
2
2
  from phub import Client
3
- from phub import literals
4
-
3
+ from base_api.modules.config import config
4
+ from base_api.base import BaseCore
5
5
  except (ModuleNotFoundError, ImportError):
6
6
  from ...phub import Client
7
- from ...phub import literals
8
-
9
- client = Client(language="en")
7
+ from base_api.modules.config import config
8
+ from base_api.base import BaseCore
10
9
 
10
+ config.request_delay = 0
11
+ core = BaseCore(config=config)
12
+ client = Client(language="en", core=core) # Make a delay, so that PornHub isn't stressed too much
13
+ print(f"Using config:; {client.core.config.request_delay}")
11
14
 
12
15
  def test_basic_search():
13
16
  search = client.search("Mia Khalifa") # for the nostalgia
@@ -1,10 +1,13 @@
1
1
  try:
2
2
  from phub import Client
3
-
4
- except (ImportError, ModuleNotFoundError):
3
+ from base_api.modules.config import config
4
+ from base_api.base import BaseCore
5
+ except (ModuleNotFoundError, ImportError):
5
6
  from ...phub import Client
6
7
 
7
- client = Client(language="en")
8
+ config.request_delay = 0
9
+ core = BaseCore(config=config)
10
+ client = Client(language="en", core=core) # Make a delay, so that PornHub isn't stressed too much
8
11
  url = "https://de.pornhub.com/view_video.php?viewkey=ph60f99fa4b5cd7"
9
12
  video = client.get(url)
10
13
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phub
3
- Version: 4.7.8
3
+ Version: 4.7.9
4
4
  Summary: An API for Pornhub
5
5
  Author-email: Egsagon <egsagon.git@gmail.com>, EchterAlsFake <EchterAlsFake@proton.me>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,21 +0,0 @@
1
- import os
2
-
3
- try:
4
- from phub import Client
5
-
6
- except (ModuleNotFoundError, ImportError):
7
- from ...phub import Client
8
-
9
- def test_auth():
10
-
11
- email = os.getenv('EMAIL')
12
- password = os.getenv('PASSWORD')
13
-
14
- assert email and password
15
-
16
- client = Client(email, password, login = False)
17
- client.login()
18
-
19
- assert client.logged
20
-
21
- # EOF
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes