X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=resources%2Flib%2FNetflixSession.py;h=e5d32191bcb993adcf599f64d26897f14153fd02;hb=0b40c0a42d38965219d8d4c63fe40053b037841f;hp=7fcea384d88b330b07cc1c9658b201f387071f9e;hpb=ac8e4930d5a58324df62285b0c5c440833784ad4;p=plugin.video.netflix.git diff --git a/resources/lib/NetflixSession.py b/resources/lib/NetflixSession.py index 7fcea38..e5d3219 100644 --- a/resources/lib/NetflixSession.py +++ b/resources/lib/NetflixSession.py @@ -446,6 +446,11 @@ class NetflixSession: for key in self.video_list_keys: video_list_ids[key] = {} + # check if the list items are hidden behind a `value` sub key + # this is the case when we fetch the lists via POST, not via a GET preflight request + if 'value' in response_data.keys(): + response_data = response_data['value'] + # subcatogorize the lists by their context video_lists = response_data['lists'] for video_list_id in video_lists.keys(): @@ -1245,7 +1250,7 @@ class NetflixSession: 'title': episode['info']['title'], 'year': episode['info']['releaseYear'], 'genres': self.parse_genres_for_video(video=episode, genres=genres), - 'mpaa': str(episode['maturity']['rating']['board']) + ' ' + str(episode['maturity']['rating']['value']), + 'mpaa': str(episode['maturity']['rating']['board']).encode('utf-8') + ' ' + str(episode['maturity']['rating']['value']).encode('utf-8'), 'maturity': episode['maturity'], 'playcount': (0, 1)[episode['watched']], 'rating': episode['userRating'].get('average', 0) if episode['userRating'].get('average', None) != None else episode['userRating'].get('predicted', 0), @@ -1270,8 +1275,9 @@ class NetflixSession: response = self._session_get(component='browse') return BeautifulSoup(response.text, 'html.parser') - def fetch_video_list_ids (self, list_from=0, list_to=50): + def fetch_video_list_ids_via_preflight (self, list_from=0, list_to=50): """Fetches the JSON with detailed information based on the lists on the landing page (browse page) of Netflix + via the preflight (GET) request Parameters ---------- @@ -1298,14 +1304,11 @@ class NetflixSession: response = self._session_get(component='video_list_ids', params=payload, type='api') return self._process_response(response=response, component=self._get_api_url_for(component='video_list_ids')) - def fetch_search_results (self, search_str, list_from=0, list_to=10): - """Fetches the JSON which contains the results for the given search query + def fetch_video_list_ids (self, list_from=0, list_to=50): + """Fetches the JSON with detailed information based on the lists on the landing page (browse page) of Netflix Parameters ---------- - search_str : :obj:`str` - String to query Netflix search for - list_from : :obj:`int` Start entry for pagination @@ -1317,42 +1320,20 @@ class NetflixSession: :obj:`dict` of :obj:`dict` of :obj:`str` Raw Netflix API call response or api call error """ - # properly encode the search string - encoded_search_string = quote(search_str) - paths = [ - ['search', encoded_search_string, 'titles', {'from': list_from, 'to': list_to}, ['summary', 'title']], - ['search', encoded_search_string, 'titles', {'from': list_from, 'to': list_to}, 'boxarts', '_342x192', 'jpg'], - ['search', encoded_search_string, 'titles', ['id', 'length', 'name', 'trackIds', 'requestId']], - ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', {'from': list_from, 'to': list_to}, ['summary', 'title']], - ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', {'from': list_from, 'to': list_to}, 'boxarts', '_342x192', 'jpg'], - ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', ['id', 'length', 'name', 'trackIds', 'requestId']] + ['lolomo', {'from': list_from, 'to': list_to}, ['displayName', 'context', 'id', 'index', 'length']] ] - response = self._path_request(paths=paths) - return self._process_response(response=response, component='Search results') - def get_lolomo_for_kids (self): - """Fetches the lolomo ID for Kids profiles - - Returns - ------- - :obj:`str` - Kids Lolomo ID - """ - response = self._session_get(component='kids') - for cookie in response.cookies: - if cookie.name.find('lhpuuidh-browse-' + self.user_data['guid']) != -1 and cookie.name.rfind('-T') == -1: - start = unquote(cookie.value).rfind(':') - return unquote(cookie.value)[start+1:] - return None + response = self._path_request(paths=paths) + return self._process_response(response=response, component='Video list ids') - def fetch_lists_for_kids (self, lolomo, list_from=0, list_to=50): - """Fetches the JSON which contains the contents of a the video list for kids users + def fetch_search_results (self, search_str, list_from=0, list_to=10): + """Fetches the JSON which contains the results for the given search query Parameters ---------- - lolomo : :obj:`str` - Lolomo ID for the Kids profile + search_str : :obj:`str` + String to query Netflix search for list_from : :obj:`int` Start entry for pagination @@ -1365,13 +1346,19 @@ class NetflixSession: :obj:`dict` of :obj:`dict` of :obj:`str` Raw Netflix API call response or api call error """ + # properly encode the search string + encoded_search_string = quote(search_str) + paths = [ - ['lists', lolomo, {'from': list_from, 'to': list_to}, ['displayName', 'context', 'genreId', 'id', 'index', 'length']] + ['search', encoded_search_string, 'titles', {'from': list_from, 'to': list_to}, ['summary', 'title']], + ['search', encoded_search_string, 'titles', {'from': list_from, 'to': list_to}, 'boxarts', '_342x192', 'jpg'], + ['search', encoded_search_string, 'titles', ['id', 'length', 'name', 'trackIds', 'requestId']], + ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', {'from': list_from, 'to': list_to}, ['summary', 'title']], + ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', {'from': list_from, 'to': list_to}, 'boxarts', '_342x192', 'jpg'], + ['search', encoded_search_string, 'suggestions', 0, 'relatedvideos', ['id', 'length', 'name', 'trackIds', 'requestId']] ] - response = self._path_request(paths=paths) - res = self._process_response(response=response, component='Kids lists') - return self.parse_video_list_ids(response_data=res['value']) + return self._process_response(response=response, component='Search results') def fetch_video_list (self, list_id, list_from=0, list_to=20): """Fetches the JSON which contains the contents of a given video list @@ -1897,14 +1884,14 @@ class NetflixSession: User Agent for platform """ import platform - if platform == 'linux' or platform == 'linux2': - return 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' - elif platform == 'darwin': + self.log(msg='Building User Agent for platform: ' + str(platform.system()) + ' - ' + str(platform.machine())) + if platform.system() == 'Darwin': return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' - elif platform == 'win32': + if platform.system() == 'Windows': return 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' - else: - return 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' + if platform.machine().startswith('arm'): + return 'Mozilla/5.0 (X11; CrOS armv7l 7647.78.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36' + return 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' def _session_post (self, component, type='document', data={}, headers={}, params={}): """Executes a get request using requests for the current session & measures the duration of that request @@ -1960,10 +1947,6 @@ class NetflixSession: url = self._get_document_url_for(component=component) if type == 'document' else self._get_api_url_for(component=component) start = time() response = self.session.get(url=url, verify=self.verify_ssl, params=params) - for cookie in response.cookies: - if cookie.name.find('lhpuuidh-browse-' + self.user_data['guid']) != -1 and cookie.name.rfind('-T') == -1: - start = unquote(cookie.value).rfind(':') - return unquote(cookie.value)[start+1:] end = time() self.log(msg='[GET] Request for "' + url + '" took ' + str(end - start) + ' seconds') return response @@ -2224,7 +2207,6 @@ class NetflixSession: important_fields = [ 'profileName', 'isActive', - 'isFirstUse', 'isAccountOwner', 'isKids' ] @@ -2237,7 +2219,7 @@ class NetflixSession: profile.update({important_field: netflix_page_data['profiles'][profile_id]['summary'][important_field]}) avatar_base = netflix_page_data['nf'].get(netflix_page_data['profiles'][profile_id]['summary']['avatarName'], False); avatar = 'https://secure.netflix.com/ffe/profiles/avatars_v2/320x320/PICON_029.png' if avatar_base == False else avatar_base['images']['byWidth']['320']['value'] - profile.update({'avatar': avatar}) + profile.update({'avatar': avatar, 'isFirstUse': False}) profiles.update({profile_id: profile}) return profiles