Merge pull request #22 from mitchellklijs/develop

Update trakt api_key and api_secret to client_id and client_secret
pull/23/head
James 7 years ago committed by GitHub
commit 9108f623a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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
@ -135,9 +135,7 @@ class Trakt:
return False
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 +162,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]

@ -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/',

@ -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,

Loading…
Cancel
Save