Merge pull request #22 from mitchellklijs/develop

Update trakt api_key and api_secret to client_id and client_secret
pull/54/head
James 7 years ago committed by desimaniac
commit a8603af238

@ -49,13 +49,13 @@ Install Traktarr to be run with `traktarr` command.
2. Enter a name for your application; for example `Traktarr` 2. Enter a name for your application; for example `Traktarr`
3. Enter `urn:ietf:wg:oauth:2.0:oob` in the `Redirect uri` field. 3. Enter `urn:ietf:wg:oauth:2.0:oob` in the `Redirect uri` field.
4. Click "SAVE APP". 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": { "trakt": {
"api_key": "my_client_id", "client_id": "my_client_id",
"api_secret": "my_client_secret_key" "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/" "url": "http://localhost:8989/"
}, },
"trakt": { "trakt": {
"api_key": "", "client_id": "",
"api_secret": "" "client_secret": ""
} }
} }
``` ```
@ -599,14 +599,14 @@ Trakt Authentication info:
```json ```json
"trakt": { "trakt": {
"api_key": "", "client_id": "",
"api_scret": "" "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 # Usage

@ -19,17 +19,17 @@ class Trakt:
def __init__(self, cfg): def __init__(self, cfg):
self.cfg = cfg self.cfg = cfg
self.api_key = cfg.trakt.api_key self.client_id = cfg.trakt.client_id
self.api_secret = cfg.trakt.api_secret self.client_secret = cfg.trakt.client_secret
self.headers = { self.headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'trakt-api-version': '2', '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: 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} payload = {'extended': 'full', 'limit': 1000}
# make request # make request
@ -45,7 +45,7 @@ class Trakt:
return True return True
return False return False
except Exception: except Exception:
log.exception("Exception validating api_key: ") log.exception("Exception validating client_id: ")
return False return False
############################################################ ############################################################
@ -55,7 +55,7 @@ class Trakt:
def __oauth_request_device_code(self): def __oauth_request_device_code(self):
log.info("We're talking to Trakt to get your verification code. Please wait a moment...") 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 # Request device code
req = requests.post('https://api.trakt.tv/oauth/device/code', params=payload, headers=self.headers) 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, log.debug('Polling Trakt for the %sth time; %s seconds left', tries,
polling_expire - round(time.time() - polling_start)) 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'} 'grant_type': 'authorization_code'}
# Poll Trakt for access token # Poll Trakt for access token
@ -135,9 +135,7 @@ class Trakt:
return False return False
def __oauth_refresh_access_token(self, refresh_token): 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,
payload = {'refresh_token': refresh_token, 'client_id': self.api_key, 'client_secret': self.api_secret,
'grant_type': 'refresh_token'} 'grant_type': 'refresh_token'}
req = requests.post('https://api.trakt.tv/oauth/token', params=payload, headers=self.headers) req = requests.post('https://api.trakt.tv/oauth/token', params=payload, headers=self.headers)
@ -164,11 +162,11 @@ class Trakt:
if user is None: if user is None:
users = self.cfg['trakt'] users = self.cfg['trakt']
if 'api_key' in users.keys(): if 'client_id' in users.keys():
users.pop('api_key') users.pop('client_id')
if 'api_secret' in users.keys(): if 'client_secret' in users.keys():
users.pop('api_secret') users.pop('client_secret')
if len(users) > 0: if len(users) > 0:
user = list(users.keys())[0] user = list(users.keys())[0]

@ -38,8 +38,8 @@ class Config(object, metaclass=Singleton):
'debug': False 'debug': False
}, },
'trakt': { 'trakt': {
'api_key': '', 'client_id': '',
'api_secret': '' 'client_secret': ''
}, },
'sonarr': { 'sonarr': {
'url': 'http://localhost:8989/', 'url': 'http://localhost:8989/',

@ -101,9 +101,9 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
if folder: if folder:
cfg['sonarr']['root_folder'] = folder cfg['sonarr']['root_folder'] = folder
# validate trakt api_key # validate trakt client_id
trakt = Trakt(cfg) 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") log.error("Aborting due to failure to validate Trakt API Key")
if notifications: if notifications:
callback_notify({'event': 'abort', 'type': 'shows', 'list_type': list_type, 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 # validate trakt api_key
trakt = Trakt(cfg) 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") log.error("Aborting due to failure to validate Trakt API Key")
if notifications: if notifications:
callback_notify({'event': 'abort', 'type': 'movies', 'list_type': list_type, callback_notify({'event': 'abort', 'type': 'movies', 'list_type': list_type,

Loading…
Cancel
Save