Skip to content

Commit 40b2a94

Browse files
committed
- fixed pagination when searching
1 parent c137eb4 commit 40b2a94

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "phub"
3-
version = "4.8.4"
3+
version = "4.8.5"
44
description = "An API for Pornhub"
55
authors = [
66
{name = 'Egsagon', email = "[email protected]"},

src/phub/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def search(self,
361361
AssertioneError: If one or more filters don't match their literals.
362362
'''
363363

364-
query = query.strip()
364+
query = query.strip().lower()
365365

366366
assert query, 'Query must be a non-empty string'
367367

@@ -370,7 +370,7 @@ def search(self,
370370
literals.ass('exclude_category', exclude_category, literals.category )
371371
literals.ass('sort' , sort , literals.sort )
372372
literals.ass('period' , period , literals.period )
373-
373+
s = f'search "{query}"'
374374
return queries.VideoQuery(
375375
client = self,
376376
func = 'video/search',
@@ -383,8 +383,7 @@ def search(self,
383383
't': literals.map.period.get(period),
384384
'hd': literals._craft_boolean(hd)
385385
},
386-
query_repr = query
387-
)
386+
query_repr = s)
388387

389388
def get_playlist(self, playlist: Union[str, int, Playlist]) -> Playlist:
390389
'''

src/phub/objects/query.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from base_api.base import setup_logger
66
from functools import cache, cached_property
77
from typing import TYPE_CHECKING, Iterator, Any, Callable, Union
8+
from urllib.parse import urlencode, urlsplit, parse_qsl, urlunsplit
89

910
from . import Video, User, FeedItem
1011

@@ -93,7 +94,6 @@ def __init__(self,
9394
self._query_repr = query_repr
9495

9596
# Build URL
96-
args |= {'page': '{page}'}
9797
self.url = utils.concat(self.BASE, func, utils.urlify(args))
9898

9999
self.suppress_spicevids = True
@@ -181,14 +181,17 @@ def _get_raw_page(self, index: int) -> str:
181181
Returns:
182182
str: The raw page content.
183183
'''
184-
184+
185185
assert isinstance(index, int)
186-
url = self.url.format(page = index + 1)
186+
parts = list(urlsplit(self.url))
187+
q = dict(parse_qsl(parts[3], keep_blank_values=True))
188+
q['page'] = str(index + 1) # PH uses 1-based pages; omit or set "1" for page 1
189+
parts[3] = urlencode(q)
190+
url = urlunsplit(parts)
191+
187192
req = self.client.call(url, get_response=True, throw=False)
188-
189193
if req.status_code == 404:
190194
raise errors.NoResult()
191-
192195
return req.text
193196

194197
@cache

0 commit comments

Comments
 (0)