Skip to content

Commit

Permalink
Merge pull request #49 from anxdpanic/pr_matrix
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
anxdpanic authored Dec 5, 2020
2 parents 37e2a46 + 0d0aaad commit 390c1f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.tubed.api" name="Tubed API" version="1.0.0" provider-name="anxdpanic">
<addon id="script.module.tubed.api" name="Tubed API" version="1.0.1" provider-name="anxdpanic">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.12.4"/>
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/src/tubed_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
API_KEY = ''
CLIENT_ID = ''
CLIENT_SECRET = ''
HTTP_REFERRER = ''

__all__ = ['ACCESS_TOKEN', 'API_KEY', 'CLIENT_ID', 'CLIENT_SECRET',
__all__ = ['ACCESS_TOKEN', 'API_KEY', 'CLIENT_ID', 'CLIENT_SECRET', 'HTTP_REFERRER',
'oauth', 'usher', 'utils', 'v3', 'exceptions']
15 changes: 15 additions & 0 deletions resources/lib/src/tubed_api/oauth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def __init__(self, client_id='', client_secret=''):
self.client_id = CLIENT_ID
self.client_secret = CLIENT_SECRET

from .. import HTTP_REFERRER
self.http_referrer = HTTP_REFERRER

def request_codes(self, scope=None):
headers = {
'Host': 'accounts.google.com',
Expand All @@ -38,6 +41,9 @@ def request_codes(self, scope=None):
'Content-Type': 'application/x-www-form-urlencoded'
}

if self.http_referrer:
headers['Referer'] = self.http_referrer

if not scope:
scope = scopes.YOUTUBE

Expand Down Expand Up @@ -83,6 +89,9 @@ def request_access_token(self, code):
'Content-Type': 'application/x-www-form-urlencoded'
}

if self.http_referrer:
headers['Referer'] = self.http_referrer

data = {
'client_id': self.client_id,
'client_secret': self.client_secret,
Expand Down Expand Up @@ -129,6 +138,9 @@ def refresh_token(self, token):
'Content-Type': 'application/x-www-form-urlencoded'
}

if self.http_referrer:
headers['Referer'] = self.http_referrer

data = {
'client_id': self.client_id,
'client_secret': self.client_secret,
Expand Down Expand Up @@ -170,6 +182,9 @@ def revoke_token(self, token):
'Content-Type': 'application/x-www-form-urlencoded'
}

if self.http_referrer:
headers['Referer'] = self.http_referrer

data = {
'token': token
}
Expand Down
10 changes: 8 additions & 2 deletions resources/lib/src/tubed_api/v3/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class V3Query(Query):
_base_url = 'https://www.googleapis.com/youtube/v3/'

def __init__(self, method, path, parameters=None, data=None, headers=None, unauthorized=False):
# pylint: disable=import-outside-toplevel

if parameters is None:
parameters = {}
else:
Expand All @@ -104,8 +106,9 @@ def __init__(self, method, path, parameters=None, data=None, headers=None, unaut
else:
headers = deepcopy(headers)

from .. import ACCESS_TOKEN # pylint: disable=import-outside-toplevel
from .. import API_KEY # pylint: disable=import-outside-toplevel
from .. import ACCESS_TOKEN
from .. import API_KEY
from .. import HTTP_REFERRER

if API_KEY:
parameters.update({
Expand All @@ -119,6 +122,9 @@ def __init__(self, method, path, parameters=None, data=None, headers=None, unaut
'Accept-Encoding': 'gzip, deflate'
})

if HTTP_REFERRER:
headers['Referer'] = HTTP_REFERRER

if method.lower() == 'post':
headers.update({
'Content-Type': 'application/json'
Expand Down

0 comments on commit 390c1f4

Please sign in to comment.