def _perform_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True, json=None): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = { 'Host': 'api.breakmedia.com', 'Connection': 'Keep-Alive', 'User-Agent': '' } _headers.update(headers) # url _url = 'http://api.breakmedia.com/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) elif method == 'POST': if post_data: result = requests.post(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif json: result = requests.post(_url, json=json, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} return result.json()
def generate_user_code(self, client_id=''): headers = {'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} _client_id = client_id if not client_id: _client_id = self._config['id'] post_data = {'client_id': _client_id, 'scope': 'https://www.googleapis.com/auth/youtube'} # 'scope': 'http://gdata.youtube.com https://www.googleapis.com/auth/youtube-paid-content'} # url url = 'https://www.youtube.com/o/oauth2/device/code' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): return result.json() return None
def generate_user_code(self, client_id=''): headers = {'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} _client_id = client_id if not client_id: _client_id = self._config['id'] post_data = {'client_id': _client_id, 'scope': 'https://www.googleapis.com/auth/youtube'} # 'scope': 'http://gdata.youtube.com https://www.googleapis.com/auth/youtube-paid-content'} # url url = 'https://www.youtube.com/o/oauth2/device/code' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): return result.json() return None
def revoke(self, refresh_token): headers = { 'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6' } post_data = {'token': refresh_token} # url url = 'https://www.youtube.com/o/oauth2/revoke' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: log_error('revoke') raise LoginException('Logout Failed') pass
def _perform_v3_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True, quota_optimized=True): # first set the config for the corresponding system (Frodo, Gotham, Helix, ...) yt_config = self._config # in any case of these APIs we change the config to a common key to save some quota # if quota_optimized and path in ['channels', 'search']: # yt_config = self.CONFIGS['youtube-for-kodi-quota'] # pass # params if not params: params = {} pass _params = {'key': yt_config['key']} _params.update(params) # headers if not headers: headers = {} pass _headers = {'Host': 'www.googleapis.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.36 Safari/537.36', 'Accept-Encoding': 'gzip, deflate'} # a config can decide if a token is allowed if self._access_token and yt_config.get('token-allowed', True): _headers['Authorization'] = 'Bearer %s' % self._access_token pass _headers.update(headers) # url _url = 'https://www.googleapis.com/youtube/v3/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': _headers['content-type'] = 'application/json' result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': _headers['content-type'] = 'application/json' result = requests.put(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.headers.get('content-type', '').startswith('application/json'): return result.json() pass
def _perform_request(self, channel_config=None, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params _params = {} if not params: params = {} pass _params.update(params) # headers if not headers: headers = {} pass _headers = { 'Accept': 'application/json', 'Origin': 'http://www.nowtv.de', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36', 'DNT': '1', 'Referer': 'http://www.nowtv.de/', 'Accept-Encoding': 'gzip', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6' } if channel_config: _headers['Referer'] = 'http://www.nowtv.de/%s' % channel_config['id'] pass # set the login token if self._token: _headers['X-AUTH-TOKEN'] = self._token pass _headers.update(headers) # url _url = 'https://api.nowtv.de/v3/' if path: _url = _url + path.strip('/') pass result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects,timeout=100) pass elif method == 'POST': result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects,timeout=100) pass elif method == 'OPTIONS': requests.options(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects,timeout=100) return {} elif method == 'DELETE': requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects,timeout=100) return {} if result is None: return {} return result.json()
def _perform_v1_tv_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {'key': self._config_tv['key']} _params.update(params) # headers if not headers: headers = {} pass _headers = {'Host': 'www.googleapis.com', 'Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36', 'Origin': 'https://www.youtube.com', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} if self._access_token_tv: _headers['Authorization'] = 'Bearer %s' % self._access_token_tv pass _headers.update(headers) # url _url = 'https://www.googleapis.com/youtubei/v1/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': _headers['content-type'] = 'application/json' result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': _headers['content-type'] = 'application/json' result = requests.put(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.headers.get('content-type', '').startswith('application/json'): return result.json() pass
def refresh_token(self, refresh_token, client_id='', client_secret='', grant_type=''): headers = { 'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6' } _client_id = client_id if not client_id: _client_id = self._config['id'] pass _client_secret = client_secret if not _client_secret: _client_secret = self._config['secret'] pass post_data = { 'client_id': _client_id, 'client_secret': _client_secret, 'refresh_token': refresh_token, 'grant_type': 'refresh_token' } # url url = 'https://www.youtube.com/o/oauth2/token' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: log_error('refresh_token') raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): json_data = result.json() access_token = json_data['access_token'] expires_in = time.time() + int(json_data.get('expires_in', 3600)) return access_token, expires_in return '', ''
def _perform_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True, json=None): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = {'Host': 'api.breakmedia.com', 'Connection': 'Keep-Alive', 'User-Agent': ''} _headers.update(headers) # url _url = 'http://api.breakmedia.com/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) elif method == 'POST': if post_data: result = requests.post(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif json: result = requests.post(_url, json=json, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} return result.json()
def _perform_v3_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {'key': self._key} _params.update(params) # headers if not headers: headers = {} pass _headers = {'Host': 'www.googleapis.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.36 Safari/537.36', 'Accept-Encoding': 'gzip, deflate', 'X-JavaScript-User-Agent': 'Google APIs Explorer'} if self._access_token: _headers['Authorization'] = 'Bearer %s' % self._access_token pass _headers.update(headers) # url _url = 'https://www.googleapis.com/youtube/v3/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': _headers['content-type'] = 'application/json' result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': _headers['content-type'] = 'application/json' result = requests.put(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.headers.get('content-type', '').startswith('application/json'): return result.json() pass
def get_device_token(self, code, context, client_id='', client_secret='', grant_type=''): headers = { 'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6' } _client_id = client_id if not client_id: _client_id = self._config['id'] pass _client_secret = client_secret if not _client_secret: _client_secret = self._config['secret'] pass post_data = { 'client_id': _client_id, 'client_secret': _client_secret, 'code': code, 'grant_type': 'http://oauth.net/grant_type/device/1.0' } # url url = 'https://www.youtube.com/o/oauth2/token' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: context.log_debug('Request answer: %s' % result.text) raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): return result.json() return None
def authenticate(self, username, password): headers = { 'device': '38c6ee9a82b8b10a', 'app': 'com.google.android.youtube', 'User-Agent': 'GoogleAuth/1.4 (GT-I9100 KTU84Q)', 'content-type': 'application/x-www-form-urlencoded', 'Host': 'android.clients.google.com', 'Connection': 'Keep-Alive', 'Accept-Encoding': 'gzip' } post_data = { 'device_country': self._country.lower(), 'operatorCountry': self._country.lower(), 'lang': self._language.replace('-', '_'), 'sdk_version': '19', # 'google_play_services_version': '6188034', 'accountType': 'HOSTED_OR_GOOGLE', 'Email': username.encode('utf-8'), 'service': 'oauth2:https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/emeraldsea.mobileapps.doritos.cookie https://www.googleapis.com/auth/plus.stream.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.pages.manage https://www.googleapis.com/auth/identity.plus.page.impersonation', 'source': 'android', 'androidId': '38c6ee9a82b8b10a', 'app': 'com.google.android.youtube', # 'client_sig': '24bb24c05e47e0aefa68a58a766179d9b613a600', 'callerPkg': 'com.google.android.youtube', # 'callerSig': '24bb24c05e47e0aefa68a58a766179d9b613a600', 'Passwd': password.encode('utf-8') } # url url = 'https://android.clients.google.com/auth' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: log_error('authenticate') raise LoginException('Login Failed') lines = result.text.replace('\n', '&') params = dict(urlparse.parse_qsl(lines)) token = params.get('Auth', '') expires = int(params.get('Expiry', -1)) if not token or expires == -1: raise LoginException('Failed to get token') return token, expires
def _perform_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass if self._client_id: params['client_id'] = self._client_id pass # basic header _headers = {'Accept-Encoding': 'gzip', 'Host': 'api.soundcloud.com:443', 'Connection': 'Keep-Alive', 'User-Agent': 'SoundCloud-Android/14.10.01-27 (Android 4.4.4; samsung GT-I9100'} # set access token if self._access_token: _headers['Authorization'] = 'OAuth %s' % self._access_token pass if not headers: headers = {} pass _headers.update(headers) # url _url = 'https://api.soundcloud.com:443/%s' % path result = None if method == 'GET': result = requests.get(_url, params=params, headers=_headers, verify=False, allow_redirects=allow_redirects) elif method == 'POST': result = requests.post(_url, data=post_data, params=params, headers=_headers, verify=False, allow_redirects=allow_redirects) elif method == 'PUT': result = requests.put(_url, data=post_data, params=params, headers=_headers, verify=False, allow_redirects=allow_redirects) elif method == 'DELETE': result = requests.delete(_url, data=post_data, params=params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.status_code == requests.codes.unauthorized: raise ClientException(status_code=result.status_code) return result.json()
def _perform_v1_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = {'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.0.1; GT-I9505 Build/LRX22C)', 'Host': 'api.redbull.tv', 'Connection': 'Keep-Alive', 'Accept-Encoding': 'gzip'} _headers.update(headers) # url _url = 'https://api.redbull.tv/v1/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': _headers['content-type'] = 'application/json' result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': _headers['content-type'] = 'application/json' result = requests.put(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.headers.get('content-type', '').startswith('application/json'): return result.json() pass
def _perform_v2_request(self, url, method='GET', headers=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = { 'User-Agent': 'VimeoAndroid/1.1.42 (Android ver=4.4.2 sdk=19; Model samsung GT-I9505; Linux 3.4.0-3423977 armv7l)', 'Host': 'vimeo.com', 'Accept-Encoding': 'gzip, deflate'} _headers.update(headers) oauth_parms = post_data or params _headers.update(self._create_authorization(url, method, oauth_parms)) # url _url = url result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': result = requests.post(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': result = requests.put(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} return result.text
def _perform_request(self, url, method='GET', headers=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = { 'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9505 Build/KOT49H)', 'Accept-Encoding': 'gzip'} _headers.update(headers) # url _url = url result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': result = requests.post(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': result = requests.put(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} return result.json()
def authenticate(self, username, password): headers = {'device': '38c6ee9a82b8b10a', 'app': 'com.google.android.youtube', 'User-Agent': 'GoogleAuth/1.4 (GT-I9100 KTU84Q)', 'content-type': 'application/x-www-form-urlencoded', 'Host': 'android.clients.google.com', 'Connection': 'Keep-Alive', 'Accept-Encoding': 'gzip'} post_data = {'device_country': self._country.lower(), 'operatorCountry': self._country.lower(), 'lang': self._language.replace('-', '_'), 'sdk_version': '19', # 'google_play_services_version': '6188034', 'accountType': 'HOSTED_OR_GOOGLE', 'Email': username.encode('utf-8'), 'service': 'oauth2:https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/emeraldsea.mobileapps.doritos.cookie https://www.googleapis.com/auth/plus.stream.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.pages.manage https://www.googleapis.com/auth/identity.plus.page.impersonation', 'source': 'android', 'androidId': '38c6ee9a82b8b10a', 'app': 'com.google.android.youtube', # 'client_sig': '24bb24c05e47e0aefa68a58a766179d9b613a600', 'callerPkg': 'com.google.android.youtube', # 'callerSig': '24bb24c05e47e0aefa68a58a766179d9b613a600', 'Passwd': password.encode('utf-8')} # url url = 'https://android.clients.google.com/auth' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: log_error('authenticate') raise LoginException('Login Failed') lines = result.text.replace('\n', '&') params = dict(urlparse.parse_qsl(lines)) token = params.get('Auth', '') expires = int(params.get('Expiry', -1)) if not token or expires == -1: raise LoginException('Failed to get token') return token, expires
def refresh_token(self, refresh_token, client_id='', client_secret='', grant_type=''): headers = {'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} _client_id = client_id if not client_id: _client_id = self._config['id'] pass _client_secret = client_secret if not _client_secret: _client_secret = self._config['secret'] pass post_data = {'client_id': _client_id, 'client_secret': _client_secret, 'refresh_token': refresh_token, 'grant_type': 'refresh_token'} # url url = 'https://www.youtube.com/o/oauth2/token' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: log_error('refresh_token') raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): json_data = result.json() access_token = json_data['access_token'] expires_in = time.time() + int(json_data.get('expires_in', 3600)) return access_token, expires_in return '', ''
def revoke(self, refresh_token): headers = {'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} post_data = {'token': refresh_token} # url url = 'https://www.youtube.com/o/oauth2/revoke' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: raise LoginException('Logout Failed') pass
def get_device_token(self, code, context, client_id='', client_secret='', grant_type=''): headers = {'Host': 'www.youtube.com', 'Connection': 'keep-alive', 'Origin': 'https://www.youtube.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept': '*/*', 'DNT': '1', 'Referer': 'https://www.youtube.com/tv', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6'} _client_id = client_id if not client_id: _client_id = self._config['id'] pass _client_secret = client_secret if not _client_secret: _client_secret = self._config['secret'] pass post_data = {'client_id': _client_id, 'client_secret': _client_secret, 'code': code, 'grant_type': 'http://oauth.net/grant_type/device/1.0'} # url url = 'https://www.youtube.com/o/oauth2/token' result = requests.post(url, data=post_data, headers=headers, verify=False) if result.status_code != requests.codes.ok: context.log_debug('Request answer: %s' % result.text) raise LoginException('Login Failed') if result.headers.get('content-type', '').startswith('application/json'): return result.json() return None
def _perform_request(self, channel_config=None, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True): # params _params = {} if not params: params = {} pass _params.update(params) # headers if not headers: headers = {} pass _headers = { 'Accept': 'application/json', 'Origin': 'http://www.nowtv.de', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36', 'DNT': '1', 'Referer': 'http://www.nowtv.de/', 'Accept-Encoding': 'gzip', 'Accept-Language': 'en-US,en;q=0.8,de;q=0.6' } if channel_config: _headers[ 'Referer'] = 'http://www.nowtv.de/%s' % channel_config['id'] pass # set the login token if self._token: _headers['X-AUTH-TOKEN'] = self._token pass _headers.update(headers) # url _url = 'https://api.nowtv.de/v3/' if path: _url = _url + path.strip('/') pass result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects, timeout=100) pass elif method == 'POST': result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects, timeout=100) pass elif method == 'OPTIONS': requests.options(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects, timeout=100) return {} elif method == 'DELETE': requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects, timeout=100) return {} if result is None: return {} return result.json()
def _perform_v2_request(self, url, method='GET', headers=None, post_data=None, params=None, allow_redirects=True): # params if not params: params = {} pass _params = {} _params.update(params) # headers if not headers: headers = {} pass _headers = { 'User-Agent': 'VimeoAndroid/1.1.42 (Android ver=4.4.2 sdk=19; Model samsung GT-I9505; Linux 3.4.0-3423977 armv7l)', 'Host': 'vimeo.com', 'Accept-Encoding': 'gzip, deflate' } _headers.update(headers) oauth_parms = post_data or params _headers.update(self._create_authorization(url, method, oauth_parms)) # url _url = url result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': result = requests.post(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': result = requests.put(_url, data=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} return result.text
def _perform_v3_request( self, method="GET", headers=None, path=None, post_data=None, params=None, allow_redirects=True, quota_optimized=True, ): # first set the config for the corresponding system (Frodo, Gotham, Helix, ...) yt_config = self._config # in any case of these APIs we change the config to a common key to save some quota if quota_optimized and path in ["channels", "search"]: yt_config = self.CONFIGS["youtube-for-kodi-quota"] pass # params if not params: params = {} pass _params = {"key": yt_config["key"]} _params.update(params) # headers if not headers: headers = {} pass _headers = { "Host": "www.googleapis.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.36 Safari/537.36", "Accept-Encoding": "gzip, deflate", } # a config can decide if a token is allowed if self._access_token and yt_config.get("token-allowed", True): _headers["Authorization"] = "Bearer %s" % self._access_token pass _headers.update(headers) # url _url = "https://www.googleapis.com/youtube/v3/%s" % path.strip("/") result = None if method == "GET": result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == "POST": _headers["content-type"] = "application/json" result = requests.post( _url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass elif method == "PUT": _headers["content-type"] = "application/json" result = requests.put( _url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass elif method == "DELETE": result = requests.delete( _url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass if result is None: return {} if result.headers.get("content-type", "").startswith("application/json"): return result.json() pass
def _perform_v3_request(self, method='GET', headers=None, path=None, post_data=None, params=None, allow_redirects=True, quota_optimized=True): # first set the config for the corresponding system (Frodo, Gotham, Helix, ...) yt_config = self._config # in any case of these APIs we change the config to a common key to save some quota if quota_optimized and path in ['channels', 'search']: yt_config = self.CONFIGS['youtube-for-kodi-quota'] pass # params if not params: params = {} pass _params = {'key': yt_config['key']} _params.update(params) # headers if not headers: headers = {} pass _headers = { 'Host': 'www.googleapis.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.36 Safari/537.36', 'Accept-Encoding': 'gzip, deflate' } # a config can decide if a token is allowed if self._access_token and yt_config.get('token-allowed', True): _headers['Authorization'] = 'Bearer %s' % self._access_token pass _headers.update(headers) # url _url = 'https://www.googleapis.com/youtube/v3/%s' % path.strip('/') result = None if method == 'GET': result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'POST': _headers['content-type'] = 'application/json' result = requests.post(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'PUT': _headers['content-type'] = 'application/json' result = requests.put(_url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == 'DELETE': result = requests.delete(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass if result is None: return {} if result.headers.get('content-type', '').startswith('application/json'): return result.json() pass
def _perform_v1_tv_request( self, method="GET", headers=None, path=None, post_data=None, params=None, allow_redirects=True ): # params if not params: params = {} pass _params = {"key": self._config_tv["key"]} _params.update(params) # headers if not headers: headers = {} pass _headers = { "Host": "www.googleapis.com", "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36", "Origin": "https://www.youtube.com", "Accept": "*/*", "DNT": "1", "Referer": "https://www.youtube.com/tv", "Accept-Encoding": "gzip", "Accept-Language": "en-US,en;q=0.8,de;q=0.6", } if self._access_token_tv: _headers["Authorization"] = "Bearer %s" % self._access_token_tv pass _headers.update(headers) # url _url = "https://www.googleapis.com/youtubei/v1/%s" % path.strip("/") result = None if method == "GET": result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects) pass elif method == "POST": _headers["content-type"] = "application/json" result = requests.post( _url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass elif method == "PUT": _headers["content-type"] = "application/json" result = requests.put( _url, json=post_data, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass elif method == "DELETE": result = requests.delete( _url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects ) pass if result is None: return {} if result.headers.get("content-type", "").startswith("application/json"): return result.json() pass