Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    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
Ejemplo n.º 11
0
    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