chore(performance): Adds string parser for inline JS data & performacne profiler...
[plugin.video.netflix.git] / resources / lib / Navigation.py
index 67a59d343eb0ed209941d563ff13e533b5e79628..79efa598d22ec16fd6dec18aa78ede59b447abc8 100644 (file)
@@ -69,7 +69,7 @@ class Navigation:
             return False
         if 'action' not in params.keys():
             # show the profiles
-            self.show_profiles()
+            return self.show_profiles()
         elif params['action'] == 'video_lists':
             # list lists that contain other lists (starting point with recommendations, search, etc.)
             return self.show_video_lists()
@@ -104,13 +104,7 @@ class Navigation:
             # display the lists (recommendations, genres, etc.)
             return self.show_user_list(type=params['type'])
         elif params['action'] == 'play_video':
-            # play a video, check for adult pin if needed
-            adult_pin = None
-            if self.check_for_adult_pin(params=params):
-                adult_pin = self.kodi_helper.show_adult_pin_dialog()
-                if self.netflix_session.send_adult_pin(adult_pin=adult_pin) != True:
-                    return self.kodi_helper.show_wrong_adult_pin_notification()
-            self.play_video(video_id=params['video_id'], start_offset=params['start_offset'])
+            self.play_video(video_id=params['video_id'], start_offset=params.get('start_offset', -1))
         elif params['action'] == 'user-items' and params['type'] == 'search':
             # if the user requested a search, ask for the term
             term = self.kodi_helper.show_search_term_dialog()
@@ -163,10 +157,11 @@ class Navigation:
                 if self.netflix_session._is_size_key(key=key) == False:
                     has_search_results = search_results_raw['value']['search'][key]['titles']['length'] > 0
                     if has_search_results == False:
-                        for entry in search_results_raw['value']['search'][key]['suggestions']:
-                            if self.netflix_session._is_size_key(key=entry) == False:
-                                if search_results_raw['value']['search'][key]['suggestions'][entry]['relatedvideos']['length'] > 0:
-                                    has_search_results = True
+                        if search_results_raw['value']['search'][key].get('suggestions', False) != False:
+                            for entry in search_results_raw['value']['search'][key]['suggestions']:
+                                if self.netflix_session._is_size_key(key=entry) == False:
+                                    if search_results_raw['value']['search'][key]['suggestions'][entry]['relatedvideos']['length'] > 0:
+                                        has_search_results = True
 
 
         # display that we haven't found a thing
@@ -258,7 +253,7 @@ class Navigation:
         # sort seasons by index by default (they´re coming back unsorted from the api)
         seasons_sorted = []
         for season_id in season_list:
-            seasons_sorted.append(int(season_list[season_id]['shortName'].split(' ')[1]))
+            seasons_sorted.append(int(season_list[season_id]['idx']))
             seasons_sorted.sort()
         return self.kodi_helper.build_season_listing(seasons_sorted=seasons_sorted, season_list=season_list, build_url=self.build_url)
 
@@ -273,8 +268,8 @@ class Navigation:
         type : :obj:`str`
             None or 'queue' f.e. when it´s a special video lists
         """
-        if self.kodi_helper.has_cached_item(cache_id=type):
-            video_list = self.kodi_helper.get_cached_item(cache_id=type)
+        if self.kodi_helper.has_cached_item(cache_id=video_list_id):
+            video_list = self.kodi_helper.get_cached_item(cache_id=video_list_id)
         else:
             raw_video_list = self.netflix_session.fetch_video_list(list_id=video_list_id)
             # check for any errors
@@ -283,7 +278,7 @@ class Navigation:
             # parse the video list ids
             if 'videos' in raw_video_list['value'].keys():
                 video_list = self.netflix_session.parse_video_list(response_data=raw_video_list)
-                self.kodi_helper.add_cached_item(cache_id=type, contents=video_list)
+                self.kodi_helper.add_cached_item(cache_id=video_list_id, contents=video_list)
             else:
                 video_list = []
         actions = {'movie': 'play_video', 'show': 'season_list'}
@@ -372,12 +367,12 @@ class Navigation:
         video = metadata['video']
 
         if video['type'] == 'movie':
-            self.library.add_movie(title=video['title'], alt_title=alt_title, year=video['year'], video_id=video_id, pin=video['requiresPin'], build_url=self.build_url)
+            self.library.add_movie(title=video['title'], alt_title=alt_title, year=video['year'], video_id=video_id, build_url=self.build_url)
         if video['type'] == 'show':
             episodes = []
             for season in video['seasons']:
                 for episode in season['episodes']:
-                    episodes.append({'season': season['seq'], 'episode': episode['seq'], 'id': episode['id'], 'pin': episode['requiresAdultVerification']})
+                    episodes.append({'season': season['seq'], 'episode': episode['seq'], 'id': episode['id']})
 
             self.library.add_show(title=video['title'], alt_title=alt_title, episodes=episodes, build_url=self.build_url)
         return self.kodi_helper.refresh()
@@ -480,21 +475,6 @@ class Navigation:
         current_profile_id = self.netflix_session.user_data['guid']
         return 'profile_id' in params and current_profile_id != params['profile_id']
 
-    def check_for_adult_pin (self, params):
-        """Checks if an adult pin is given in the query params
-
-        Parameters
-        ----------
-        params : :obj:`dict` of :obj:`str`
-            Url query params
-
-        Returns
-        -------
-        bool
-            Adult pin parameter exists or not
-        """
-        return (True, False)[params['pin'] == 'True']
-
     def parse_paramters (self, paramstring):
         """Tiny helper to convert a url paramstring into a dictionary