Skip to content

Commit

Permalink
Fix recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
Egsago-n committed Feb 29, 2024
1 parent d487fe7 commit 81dee78
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/creds*
build/*
src/test*.py
docs/build/*
4 changes: 2 additions & 2 deletions src/phub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
## PHUB v4.4
## PHUB v4.5.3
See https://phub.readthedocs.io/en/latest/ for docs.
See https://github.com/EchterAlsFake/PHUB for code.
Expand All @@ -9,7 +9,7 @@
__author__ = 'Egsagon, EchterAlsFake'
__copyright__ = 'Copyright 2024, PHUB'
__license__ = 'GPLv3'
__version__ = '4.4'
__version__ = '4.5.3'

__all__ = ['Client', 'Quality', 'core', 'utils',
'consts', 'errors', 'objects', 'modules']
Expand Down
9 changes: 9 additions & 0 deletions src/phub/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0'
}

COOKIES = {
'accessAgeDisclaimerPH': '1',
'accessAgeDisclaimerUK': '1',
'accessPH': '1',
'age_verified': '1',
'cookieBannerState': '1',
'platform': 'pc'
}

LOGIN_PAYLOAD = {
'from': 'pc_login_modal_:homepage_redesign',
}
Expand Down
9 changes: 3 additions & 6 deletions src/phub/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ def reset(self) -> None:
self.session = requests.Session()
self._clear_granted_token()

# Bypass age disclaimer
self.session.cookies.set('accessAgeDisclaimerPH', '1')
self.session.cookies.set('accessAgeDisclaimerUK', '1')
self.session.cookies.set('accessPH', '1')
self.session.cookies.set('age_verified', '1')

# Insert cookies
self.session.cookies.update(consts.COOKIES)

def call(self,
func: str,
method: str = 'GET',
Expand Down
20 changes: 20 additions & 0 deletions src/phub/objects/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ def refresh(self, refresh_login: bool = False) -> None:
logger.debug('Deleting key %s', key)
delattr(self, key)

def fix_recommendations(self) -> None:
'''
Allow recommandations cookies.
'''

logger.info('Fixing account recommendations')

payload = utils.urlify({
'token': self.client._granted_token,
'cookie_selection': 3,
'site_id': 1
})

res = self.client.call('user/log_user_cookie_consent' + payload, silent = True)

assert res.json().get('success')

@cached_property
def recommended(self) -> queries.VideoQuery:
'''
Expand All @@ -112,6 +129,9 @@ def recommended(self) -> queries.VideoQuery:

from . import queries

# Called each account refresh
self.fix_recommendations()

return queries.VideoQuery(self.client, 'recommended')

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion src/phub/objects/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _parse_item(self, raw: str) -> Video:

obj.data = {
# Property overrides
'page@title': data["title"],
'page@video_title': data["title"],
'data@thumb': data["image"],
'page@id': id,

Expand Down

0 comments on commit 81dee78

Please sign in to comment.