X-Git-Url: http://git.code-monkey.de/?p=plugin.video.netflix.git;a=blobdiff_plain;f=resources%2Flib%2FNetflixSession.py;h=a4c48744ef7a933cd6e0cc18ef2dc8b9a0dc4929;hp=69c848f666f1761e14cc6c501321cd1faae39182;hb=385854355a756f1689ef897443876e4f75ace542;hpb=c6e56c0365952da48fa6678c83497fecdb5d73e6 diff --git a/resources/lib/NetflixSession.py b/resources/lib/NetflixSession.py index 69c848f..a4c4874 100644 --- a/resources/lib/NetflixSession.py +++ b/resources/lib/NetflixSession.py @@ -10,7 +10,7 @@ from urllib import quote, unquote from time import time from base64 import urlsafe_b64encode from bs4 import BeautifulSoup, SoupStrainer -from utils import noop +from utils import noop, get_user_agent_for_current_platform try: import cPickle as pickle except: @@ -103,7 +103,7 @@ class NetflixSession: # start session, fake chrome on the current platform (so that we get a proper widevine esn) & enable gzip self.session = session() self.session.headers.update({ - 'User-Agent': self._get_user_agent_for_current_platform(), + 'User-Agent': get_user_agent_for_current_platform(), 'Accept-Encoding': 'gzip' }) @@ -1074,14 +1074,29 @@ class NetflixSession: } } """ - seasons = {} raw_seasons = response_data['value'] + videos = raw_seasons['videos'] + + # get art video key + video = {} + for key, video_candidate in videos.iteritems(): + if not self._is_size_key(key): + video = video_candidate + + # get season index + sorting = {} + for idx, season_list_entry in video['seasonList'].iteritems(): + if self._is_size_key(key=idx) == False and idx != 'summary': + sorting[int(season_list_entry[1])] = int(idx) + + seasons = {} + for season in raw_seasons['seasons']: if self._is_size_key(key=season) == False: - seasons.update(self.parse_season_entry(season=raw_seasons['seasons'][season], videos=raw_seasons['videos'])) + seasons.update(self._parse_season_entry(season=raw_seasons['seasons'][season], video=video, sorting=sorting)) return seasons - def parse_season_entry (self, season, videos): + def _parse_season_entry (self, season, video, sorting): """Parse a season list entry e.g. rip out the parts we need Parameters @@ -1107,16 +1122,6 @@ class NetflixSession: } } """ - # get art video key - video_key = '' - for key in videos.keys(): - if self._is_size_key(key=key) == False: - video_key = key - # get season index - sorting = {} - for idx in videos[video_key]['seasonList']: - if self._is_size_key(key=idx) == False and idx != 'summary': - sorting[int(videos[video_key]['seasonList'][idx][1])] = int(idx) return { season['summary']['id']: { 'idx': sorting[season['summary']['id']], @@ -1124,10 +1129,10 @@ class NetflixSession: 'text': season['summary']['name'], 'shortName': season['summary']['shortName'], 'boxarts': { - 'small': videos[video_key]['boxarts']['_342x192']['jpg']['url'], - 'big': videos[video_key]['boxarts']['_1280x720']['jpg']['url'] + 'small': video['boxarts']['_342x192']['jpg']['url'], + 'big': video['boxarts']['_1280x720']['jpg']['url'] }, - 'interesting_moment': videos[video_key]['interestingMoment']['_665x375']['jpg']['url'], + 'interesting_moment': video['interestingMoment']['_665x375']['jpg']['url'], } } @@ -1880,24 +1885,6 @@ class NetflixSession: """ return urlsafe_b64encode(account['email']) - def _get_user_agent_for_current_platform (self): - """Determines the user agent string for the current platform (to retrieve a valid ESN) - - Returns - ------- - :obj:`str` - User Agent for platform - """ - import platform - 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' - 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' - 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