From 2182f4fbb93dc70d62b688b66a7ca245a388f5d2 Mon Sep 17 00:00:00 2001 From: Mitchell Klijs Date: Thu, 3 May 2018 09:11:38 +0200 Subject: [PATCH 1/2] Update trakt api_key and api_secret to client_id and client_secret --- README.md | 18 +++++++++--------- media/trakt.py | 26 +++++++++++++------------- misc/config.py | 4 ++-- traktarr.py | 6 +++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index d90ae7a..82d22cb 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,13 @@ Install Traktarr to be run with `traktarr` command. 2. Enter a name for your application; for example `Traktarr` 3. Enter `urn:ietf:wg:oauth:2.0:oob` in the `Redirect uri` field. 4. Click "SAVE APP". -5. Open the Traktarr configuration file `config.json` and insert the Client ID in the `api_key` and the Client Secret in the `api_secret`, like this: +5. Open the Traktarr configuration file `config.json` and insert the Client ID in the `client_id` and the Client Secret in the `client_secret`, like this: ``` { "trakt": { - "api_key": "my_client_id", - "api_secret": "my_client_secret_key" + "client_id": "my_client_id", + "client_secret": "my_client_secret_key" } } ``` @@ -206,8 +206,8 @@ To have Traktarr get Movies and Shows for you automatically, on set interval. "url": "http://localhost:8989/" }, "trakt": { - "api_key": "", - "api_secret": "" + "client_id": "", + "client_secret": "" } } ``` @@ -599,14 +599,14 @@ Trakt Authentication info: ```json "trakt": { - "api_key": "", - "api_scret": "" + "client_id": "", + "client_secret": "" } ``` -`api_key` - Fill in your Trakt API key (_Client ID_). +`client_id` - Fill in your Trakt API key (_Client ID_). -`api_secret` - Fill in your Trakt Secret key (_Client Scret_) +`client_secret` - Fill in your Trakt Secret key (_Client Scret_) # Usage diff --git a/media/trakt.py b/media/trakt.py index bd141b9..dfbbbd8 100644 --- a/media/trakt.py +++ b/media/trakt.py @@ -19,17 +19,17 @@ class Trakt: def __init__(self, cfg): self.cfg = cfg - self.api_key = cfg.trakt.api_key - self.api_secret = cfg.trakt.api_secret + self.client_id = cfg.trakt.client_id + self.client_secret = cfg.trakt.client_secret self.headers = { 'Content-Type': 'application/json', 'trakt-api-version': '2', - 'trakt-api-key': self.api_key + 'trakt-api-key': self.client_id } - def validate_api_key(self): + def validate_client_id(self): try: - # request trending shows to determine if api_key is valid + # request trending shows to determine if client_id is valid payload = {'extended': 'full', 'limit': 1000} # make request @@ -45,7 +45,7 @@ class Trakt: return True return False except Exception: - log.exception("Exception validating api_key: ") + log.exception("Exception validating client_id: ") return False ############################################################ @@ -55,7 +55,7 @@ class Trakt: def __oauth_request_device_code(self): log.info("We're talking to Trakt to get your verification code. Please wait a moment...") - payload = {'client_id': self.api_key} + payload = {'client_id': self.client_id} # Request device code req = requests.post('https://api.trakt.tv/oauth/device/code', params=payload, headers=self.headers) @@ -117,7 +117,7 @@ class Trakt: log.debug('Polling Trakt for the %sth time; %s seconds left', tries, polling_expire - round(time.time() - polling_start)) - payload = {'code': device_code, 'client_id': self.api_key, 'client_secret': self.api_secret, + payload = {'code': device_code, 'client_id': self.client_id, 'client_secret': self.client_secret, 'grant_type': 'authorization_code'} # Poll Trakt for access token @@ -137,7 +137,7 @@ class Trakt: def __oauth_refresh_access_token(self, refresh_token): # TODO Doesn't work - payload = {'refresh_token': refresh_token, 'client_id': self.api_key, 'client_secret': self.api_secret, + payload = {'refresh_token': refresh_token, 'client_id': self.client_id, 'client_secret': self.client_secret, 'grant_type': 'refresh_token'} req = requests.post('https://api.trakt.tv/oauth/token', params=payload, headers=self.headers) @@ -164,11 +164,11 @@ class Trakt: if user is None: users = self.cfg['trakt'] - if 'api_key' in users.keys(): - users.pop('api_key') + if 'client_id' in users.keys(): + users.pop('client_id') - if 'api_secret' in users.keys(): - users.pop('api_secret') + if 'client_secret' in users.keys(): + users.pop('client_secret') if len(users) > 0: user = list(users.keys())[0] diff --git a/misc/config.py b/misc/config.py index 3e3ba09..1f9dea2 100644 --- a/misc/config.py +++ b/misc/config.py @@ -38,8 +38,8 @@ class Config(object, metaclass=Singleton): 'debug': False }, 'trakt': { - 'api_key': '', - 'api_secret': '' + 'client_id': '', + 'client_secret': '' }, 'sonarr': { 'url': 'http://localhost:8989/', diff --git a/traktarr.py b/traktarr.py index ec73b0d..f87eeff 100755 --- a/traktarr.py +++ b/traktarr.py @@ -101,9 +101,9 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea if folder: cfg['sonarr']['root_folder'] = folder - # validate trakt api_key + # validate trakt client_id trakt = Trakt(cfg) - if not trakt.validate_api_key(): + if not trakt.validate_client_id(): log.error("Aborting due to failure to validate Trakt API Key") if notifications: callback_notify({'event': 'abort', 'type': 'shows', 'list_type': list_type, @@ -280,7 +280,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se # validate trakt api_key trakt = Trakt(cfg) - if not trakt.validate_api_key(): + if not trakt.validate_client_id(): log.error("Aborting due to failure to validate Trakt API Key") if notifications: callback_notify({'event': 'abort', 'type': 'movies', 'list_type': list_type, From 0b778ca8c2fbb08d4b6547123a1adb9315f19c42 Mon Sep 17 00:00:00 2001 From: Mitchell Klijs Date: Thu, 3 May 2018 12:00:24 +0200 Subject: [PATCH 2/2] Remove old TODO --- media/trakt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/media/trakt.py b/media/trakt.py index dfbbbd8..9989eb1 100644 --- a/media/trakt.py +++ b/media/trakt.py @@ -135,8 +135,6 @@ class Trakt: return False def __oauth_refresh_access_token(self, refresh_token): - # TODO Doesn't work - payload = {'refresh_token': refresh_token, 'client_id': self.client_id, 'client_secret': self.client_secret, 'grant_type': 'refresh_token'}