def get_json(self, url): #TODO: Check to see if cookie is expired and re-authenticate to get new EPGReqPayload headers = { "Accept": "*/*", "reqPayload": globals.get_setting("EPGreqPayload"), "User-Agent": globals.UA_ANDROID_TV, "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.5", "X-Requested-With": "com.snei.vue.android", "Connection": "keep-alive" } r = requests.get(url, headers=headers, cookies=globals.load_cookies(), verify=self.verify) if r.status_code != 200: print(TAG + "ERROR - could not complete json request: ") try: json_source = r.json() print(TAG + "\t" + json_source['header']['error']['message']) except: pass sys.exit() return r.json()
def login(self): url = globals.API_URL + '/ssocookie' #request a single sign on cookie headers = { "Accept": "*/*", "Content-type": "application/x-www-form-urlencoded", "Origin": "https://id.sonyentertainmentnetwork.com", "Accept-Language": "en-US, en; q=0.8", "Accept-Encoding": "deflate", "User-Agent": globals.UA_ANDROID_TV, "X-Requested-With": "com.snei.vue.atv", "Connection": "Keep-Alive" } payload = "authentication_type=password&username="******"&password="******"&client_id=" + globals.ANDROID_TV_CLIENT_ID r = requests.post(url, headers=headers, cookies=globals.load_cookies(), data=payload, verify=self.verify) json_source = r.json() globals.save_cookies(r.cookies) if 'npsso' in json_source: npsso = json_source['npsso'] globals.save_setting('npsso', npsso) self.set_profile() print(TAG + "Login success") elif 'authentication_type' in json_source: if json_source['authentication_type'] == 'two_step': ticket_uuid = json_source['ticket_uuid'] self.two_step_verification(ticket_uuid) elif 'error_description' in json_source: print(TAG + "[-] ERROR: Login error - " + json_source['error_description']) sys.exit() else: #something bas must have happened print(TAG + "[-] ERROR: Login error (generic)") sys.exit() self.write_req_payload()
def two_step_verification(self, ticket_uuid): code = raw_input("Code: ") if code == '': sys.exit() url = globals.API_URL + '/sso_cookie' headers = { "Accept": "*/*", "Content-type": "application/x-www-form-urlencoded", "Origin": "https://id.sonyentertainmentnetwork.com", "Accept-Language": "en-US, en;q=0.8", "User-Agent": globals.UA_ANDROID_TV, "Connection": "Keep-Alive", "Referer": "https://id.sonyentertainmentnetwork.com/signin/?service_entity=urn:service-entity:psn&ui=pr&service_logo=ps&response_type=code&scope=psn:s2s&client_id=" + globals.REQ_CLIENT_ID + "&request_locale=en_US&redirect_uri=https://io.playstation.com/playstation/psn/acceptLogin&error=login_required&error_code=4165&error_description=User+is+not+authenticated" } payload = 'authentication_type=two_step&ticket_uuid=' + ticket_uuid + '&code=' + code + '&client_id=' + globals.LOGIN_CLIENT_ID r = requests.post(url, headers=headers, cookies=globals.load_cookies(), data=payload, verify=verify) json_source = r.json() globals.save_cookies(r.cookies) if 'npsso' in json_source: npsso = json_source['npsso'] globals.save_setting("npsso", json_source['npsso']) print(TAG + "Two factor login success") elif 'error_description' in json_source: print(TAG + "[-] ERROR: Login error - " + json_source['error_description']) sys.exit() else: print(TAG + "[-] ERROR: Login error (generic)") sys.exit()
def get_grant_code(self): url = globals.API_URL + "/oauth/authorize" url += "?request_theme=tv" url += "&ui=ds" url += "&client_id=" + globals.REQ_CLIENT_ID url += "&hidePageElements=noAccountSelection" url += "&redirect_uri=" + urllib.quote_plus(globals.THEMIS) url += "&request_locale=en" url += "&response_type=code" url += "&resolution=1080" url += "&scope=psn%3As2s" url += "&service_logo=ps" url += "&smcid=tv%3Apsvue" url += "&duid=" + self.device_id headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-US", "User-Agent": globals.UA_ANDROID_TV, "Connection": "Keep-Alive", "X-Requested-With": "com.snei.vue.atv" } code = '' r = requests.get(url, headers=headers, allow_redirects=False, cookies=globals.load_cookies(), verify=self.verify) if "X-NP-GRANT-CODE" in r.headers: code = r.headers["X-NP-GRANT-CODE"] globals.save_cookies(r.cookies) else: print(TAG + "[-] ERROR: Could not get grant code") return code
def epg_get_stream(self, url): headers = { "Accept": "*/*", "Content-type": "application/x-www-form-urlencoded", "Origin": "https://vue.playstation.com", "Accept-Language": "en-US,en;q=0.8", "Referer": "https://vue.playstation.com/watch/live", "Accept-Encoding": "gzip, deflate, br", "User-Agent": globals.UA_ANDROID_TV, "Connection": "Keep-Alive", "Host": "media-framework.totsuko.tv", "reqPayload": globals.get_setting("EPGreqPayload"), "X-Requested-With": "com.snei.vue.android" } r = requests.get(url, headers=headers, cookies=globals.load_cookies(), verify=globals.VERIFY) json_source = r.json() stream_url = json_source['body']['video'] return stream_url