From 4dec2c9ab3433278326b1cbfe72b21fe73bc8429 Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Fri, 10 Jul 2026 15:11:27 +0200 Subject: [PATCH] wip --- .../directorybuilder/dir_path_requests.py | 43 ++++++++++++------- .../lib/services/nfsession/nfsession_ops.py | 35 +++++++-------- .../services/nfsession/session/endpoints.py | 13 +++--- .../nfsession/session/http_requests.py | 3 -- resources/lib/utils/api_paths.py | 32 +++++++------- resources/lib/utils/data_types.py | 14 +++--- 6 files changed, 75 insertions(+), 65 deletions(-) diff --git a/resources/lib/services/nfsession/directorybuilder/dir_path_requests.py b/resources/lib/services/nfsession/directorybuilder/dir_path_requests.py index 628cb0749..ee6c2bee9 100644 --- a/resources/lib/services/nfsession/directorybuilder/dir_path_requests.py +++ b/resources/lib/services/nfsession/directorybuilder/dir_path_requests.py @@ -17,7 +17,7 @@ from resources.lib.utils.api_paths import (VIDEO_LIST_PARTIAL_PATHS, RANGE_PLACEHOLDER, VIDEO_LIST_BASIC_PARTIAL_PATHS, SEASONS_PARTIAL_PATHS, EPISODES_PARTIAL_PATHS, ART_PARTIAL_PATHS, TRAILER_PARTIAL_PATHS, PATH_REQUEST_SIZE_STD, build_paths, - PATH_REQUEST_SIZE_MAX) + PATH_REQUEST_SIZE_MAX, jgraph_get) from resources.lib.common import cache_utils from resources.lib.globals import G from resources.lib.utils.logging import LOG @@ -55,16 +55,26 @@ def req_loco_list_root(self): # - To get items for the main menu # (when 'loco_known'==True and loco_contexts is set, see MAIN_MENU_ITEMS in globals.py) # - To get list items for menus that have multiple contexts set to 'loco_contexts' like 'recommendations' menu - LOG.debug('Requesting LoCo root lists') - paths = ([['loco', 'componentSummary'], - ['loco', {'from': 0, 'to': 50}, 'componentSummary'], - # Titles of first 4 videos in each video list (needed only to show titles in the plot description) - ['loco', {'from': 0, 'to': 50}, {'from': 0, 'to': 3}, 'reference', ['title', 'summary']]] + - # Art for the first video of each context list (needed only to add art to the menu item) - build_paths(['loco', {'from': 0, 'to': 50}, 0, 'reference'], ART_PARTIAL_PATHS)) + LOG.debug('Requesting LoCo\'s root ID') + paths = ([['loco', 'componentSummary']]) call_args = {'paths': paths} - path_response = self.nfsession.path_request(**call_args) - return LoCo(path_response) + loco_response = self.nfsession.path_request(**call_args) + loco_data = jgraph_get('loco', loco_response) + comp_data = jgraph_get('componentSummary', loco_data) + loco_id = comp_data.get('id') + if loco_id: + LOG.debug('Requesting LoCo root lists') + paths = ([['locos', loco_id, {'from': 0, 'to': 50}, 'componentSummary'], + # Titles of first 4 videos in each video list (needed only to show titles in the plot description) + ['locos', loco_id, {'from': 0, 'to': 50}, {'from': 0, 'to': 3}, 'reference', ['title', 'summary']]]) + # Art for the first video of each context list (needed only to add art to the menu item) + # + build_paths(['locos', loco_id, {'from': 0, 'to': 50}, 0, 'reference'], ART_PARTIAL_PATHS)) + call_args = {'paths': paths} + path_response = self.nfsession.path_request(**call_args) + return LoCo(path_response) + else: + LOG.error('Cannot get the LoCo\'s root ID, response data: {}', loco_response) + return LoCo({}) @cache_utils.cache_output(cache_utils.CACHE_GENRES, identify_from_kwarg_name='genre_id', ignore_self_class=True) def req_loco_list_genre(self, genre_id): @@ -113,9 +123,9 @@ def req_seasons(self, videoid, perpetual_range_start): raise InvalidVideoId(f'Cannot request season list for {videoid}') LOG.debug('Requesting the seasons list for show {}', videoid) call_args = { - 'paths': (build_paths(['videos', videoid.tvshowid], SEASONS_PARTIAL_PATHS) + - build_paths(['videos', videoid.tvshowid], ART_PARTIAL_PATHS) + - [['videos', videoid.tvshowid, 'componentSummary']]), + 'paths': (build_paths(['videos', videoid.tvshowid], SEASONS_PARTIAL_PATHS)), + #+ build_paths(['videos', videoid.tvshowid], ART_PARTIAL_PATHS) + + #[['videos', videoid.tvshowid, 'componentSummary']]), 'length_params': ['stdlist_wid', ['videos', videoid.tvshowid, 'seasonList']], 'perpetual_range_start': perpetual_range_start } @@ -130,9 +140,10 @@ def req_episodes(self, videoid, perpetual_range_start=None): raise InvalidVideoId(f'Cannot request episode list for {videoid}') LOG.debug('Requesting episode list for {}', videoid) paths = ([['seasons', videoid.seasonid, 'summary']] + - [['seasons', videoid.seasonid, 'componentSummary']] + - build_paths(['seasons', videoid.seasonid, 'episodes', RANGE_PLACEHOLDER], EPISODES_PARTIAL_PATHS) + - build_paths(['videos', videoid.tvshowid], ART_PARTIAL_PATHS + [[['title', 'delivery']]])) + [['videos', videoid.tvshowid, ['title', 'delivery']]] + + #[['seasons', videoid.seasonid, 'componentSummary']] + + build_paths(['seasons', videoid.seasonid, 'episodes', RANGE_PLACEHOLDER], EPISODES_PARTIAL_PATHS)) + # + build_paths(['videos', videoid.tvshowid], ART_PARTIAL_PATHS + [[['title', 'delivery']]])) call_args = { 'paths': paths, 'length_params': ['stdlist_wid', ['seasons', videoid.seasonid, 'episodes']], diff --git a/resources/lib/services/nfsession/nfsession_ops.py b/resources/lib/services/nfsession/nfsession_ops.py index 384722477..41a86982d 100644 --- a/resources/lib/services/nfsession/nfsession_ops.py +++ b/resources/lib/services/nfsession/nfsession_ops.py @@ -104,27 +104,28 @@ def activate_profile(self, guid): # Change the current profile while a video is playing can cause problems with outgoing HTTP requests # (MSL/NFSession) causing a failure in the HTTP request or sending data on the wrong profile raise ErrorMsgNoReport('It is not possible select a profile while a video is playing.') - timestamp = time.time() LOG.info('Activating profile {}', guid) - # 20/05/2020 - The method 1 not more working for switching PIN locked profiles + # INIT Method 1 - HTTP mode - # response = self._get('switch_profile', params={'tkn': guid}) - # self.nfsession.auth_url = self.website_extract_session_data(response)['auth_url'] + response = self.get_safe('switch_profile', params={'tkn': guid}) + self.auth_url = self.website_extract_session_data(response)['auth_url'] # END Method 1 - # INIT Method 2 - API mode - try: - response = self.get_safe(endpoint='activate_profile', - params={'switchProfileGuid': guid, - '_': int(timestamp * 1000), - 'authURL': self.auth_url}) - if response.get('status') != 'success': - raise InvalidProfilesError('Unable to access to the selected profile.') - except HttpError401 as exc: - # Profile guid not more valid - raise InvalidProfilesError('Unable to access to the selected profile.') from exc + + # INIT Method 2 - API mode **** 07/2026 not working anymore **** + # try: + # timestamp = time.time() + # response = self.get_safe(endpoint='activate_profile', + # params={'switchProfileGuid': guid, + # '_': int(timestamp * 1000), + # 'authURL': self.auth_url}) + # if response.get('status') != 'success': + # raise InvalidProfilesError('Unable to access to the selected profile.') + # except HttpError401 as exc: + # # Profile guid not more valid + # raise InvalidProfilesError('Unable to access to the selected profile.') from exc # Retrieve browse page to update authURL - response = self.get_safe('browse') - self.auth_url = website.extract_session_data(response)['auth_url'] + # response = self.get_safe('browse') + # self.auth_url = website.extract_session_data(response)['auth_url'] # END Method 2 G.LOCAL_DB.switch_active_profile(guid) diff --git a/resources/lib/services/nfsession/session/endpoints.py b/resources/lib/services/nfsession/session/endpoints.py index b59cbbf11..ee6485406 100644 --- a/resources/lib/services/nfsession/session/endpoints.py +++ b/resources/lib/services/nfsession/session/endpoints.py @@ -77,12 +77,13 @@ 'use_default_params': False, 'add_auth_url': None, 'accept': '*/*'}, - 'activate_profile': - {'address': '/api/shakti/mre/profiles/switch', - 'is_api_call': False, - 'use_default_params': False, - 'add_auth_url': None, - 'accept': '*/*'}, + # **** 07/2026 not working anymore **** + # 'activate_profile': + # {'address': '/api/shakti/mre/profiles/switch', + # 'is_api_call': False, + # 'use_default_params': False, + # 'add_auth_url': None, + # 'accept': '*/*'}, 'profile_lock': {'address': '/api/shakti/mre/profileLock', 'is_api_call': False, diff --git a/resources/lib/services/nfsession/session/http_requests.py b/resources/lib/services/nfsession/session/http_requests.py index 1a29df66a..cff94bf74 100644 --- a/resources/lib/services/nfsession/session/http_requests.py +++ b/resources/lib/services/nfsession/session/http_requests.py @@ -174,9 +174,6 @@ def _prepare_request_properties(self, endpoint_conf, kwargs): 'falcor_server': '0.1.0', 'withSize': 'false', 'materialize': 'false', - 'routeAPIRequestsThroughFTL': 'false', - 'isVolatileBillboardsEnabled': 'true', - 'isTop10Supported': 'true', 'original_path': '/shakti/mre/pathEvaluator' } if endpoint_conf['add_auth_url'] == 'to_params': diff --git a/resources/lib/utils/api_paths.py b/resources/lib/utils/api_paths.py index 77645712f..f3e641f4e 100644 --- a/resources/lib/utils/api_paths.py +++ b/resources/lib/utils/api_paths.py @@ -35,7 +35,7 @@ """Predefined lambda expressions that return the number of video results within a path response dict""" -ART_PARTIAL_PATHS = [ +ART_PARTIAL_PATHS = [ # art moved to graphql endpoint ['boxarts', [ART_SIZE_SD, ART_SIZE_FHD, ART_SIZE_POSTER], 'jpg', 'value'], ['interestingMoment', [ART_SIZE_SD, ART_SIZE_FHD], 'jpg', 'value'], ['artWorkByType', 'LOGO_BRANDED_HORIZONTAL', '_550x124', 'png', 'value'], # 11/05/2020 same img of bb2OGLogo @@ -48,16 +48,16 @@ VIDEO_LIST_PARTIAL_PATHS = [ - [['requestId', 'summary', 'title', 'synopsis', 'regularSynopsis', 'evidence', 'queue', 'inRemindMeList', - 'episodeCount', 'info', 'maturity', 'runtime', 'seasonCount', 'availability', 'trackIds', + [['summary', 'title', 'synopsis', 'queue', 'inRemindMeList', + 'episodeCount', 'maturity', 'runtime', 'seasonCount', 'availability', 'trackIds', 'releaseYear', 'userRating', 'numSeasonsLabel', 'bookmarkPosition', 'creditsOffset', - 'dpSupplementalMessage', 'watched', 'delivery', 'sequiturEvidence', 'promoVideo', 'availability', 'itemSummary']], - [['genres', 'tags', 'creators', 'directors', 'cast'], - {'from': 0, 'to': 10}, ['id', 'name']] -] + ART_PARTIAL_PATHS + 'delivery', 'availability', 'itemSummary']] + #,[['genres', 'tags', 'creators', 'directors', 'cast'], + # {'from': 0, 'to': 10}, ['id', 'name']] +]# + ART_PARTIAL_PATHS VIDEO_LIST_BASIC_PARTIAL_PATHS = [ - [['title', 'queue', 'watched', 'summary', 'type', 'id']] + [['queue', 'summary']] ] GENRE_PARTIAL_PATHS = [ @@ -70,20 +70,20 @@ SEASONS_PARTIAL_PATHS = [ ['seasonList', RANGE_PLACEHOLDER, 'summary'], ['title'] -] + ART_PARTIAL_PATHS +]# + ART_PARTIAL_PATHS EPISODES_PARTIAL_PATHS = [ - [['requestId', 'summary', 'synopsis', 'regularSynopsis', 'title', 'runtime', 'releaseYear', 'queue', - 'info', 'maturity', 'userRating', 'bookmarkPosition', 'creditsOffset', - 'watched', 'delivery', 'trackIds', 'availability']], - [['genres', 'tags', 'creators', 'directors', 'cast'], + [['summary', 'synopsis', 'title', 'runtime', 'releaseYear', 'queue', + 'maturity', 'userRating', 'bookmarkPosition', 'creditsOffset', + 'delivery', 'trackIds', 'availability']], + [['genres', 'creators', 'directors', 'cast'], {'from': 0, 'to': 10}, ['id', 'name']] -] + ART_PARTIAL_PATHS +]# + ART_PARTIAL_PATHS TRAILER_PARTIAL_PATHS = [ - [['availability', 'summary', 'synopsis', 'regularSynopsis', 'title', 'trackIds', 'delivery', 'runtime', + [['availability', 'summary', 'synopsis', 'title', 'trackIds', 'delivery', 'runtime', 'bookmarkPosition', 'creditsOffset']] -] + ART_PARTIAL_PATHS +]# + ART_PARTIAL_PATHS EVENT_PATHS = [ [['requestId', 'title', 'runtime', 'queue', 'bookmarkPosition', 'watched', 'trackIds']] diff --git a/resources/lib/utils/data_types.py b/resources/lib/utils/data_types.py index 914e3be5c..06d309152 100644 --- a/resources/lib/utils/data_types.py +++ b/resources/lib/utils/data_types.py @@ -335,10 +335,10 @@ def _get_titles(videos): def _filterout_loco_contexts(root_id, data, contexts): """Deletes from the data all records related to the specified contexts""" - total_items = data['locos'][root_id]['componentSummary'].get('value', {}).get('length', 0) - for index in range(total_items - 1, -1, -1): - list_id = data['locos'][root_id][str(index)]['value'][1] - if not data['lists'][list_id]['componentSummary'].get('value', {}).get('context') in contexts: - continue - del data['lists'][list_id] - del data['locos'][root_id][str(index)] + if not data: + return + lists = data['lists'] + for key in list(lists.keys()): + context = lists[key].get('componentSummary', {}).get('value', {}).get('context') + if context in contexts: + del lists[key]