mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-10 06:54:21 +00:00
[28] #800 Change Trakt Auth Process
This commit is contained in:
parent
c12aa54fec
commit
0b99b1994d
7 changed files with 26 additions and 20 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
1.16.2-develop27
|
1.16.2-develop28
|
||||||
|
|
|
@ -115,6 +115,7 @@ sonarr: # Can be individually specified
|
||||||
trakt:
|
trakt:
|
||||||
client_id: ################################################################
|
client_id: ################################################################
|
||||||
client_secret: ################################################################
|
client_secret: ################################################################
|
||||||
|
pin:
|
||||||
authorization:
|
authorization:
|
||||||
# everything below is autofilled by the script
|
# everything below is autofilled by the script
|
||||||
access_token:
|
access_token:
|
||||||
|
|
|
@ -4,6 +4,8 @@ Configuring [Radarr](https://radarr.video/) is optional but will allow you to se
|
||||||
|
|
||||||
Radarr V2 may work, but it is not supported please upgrade to V3 if you can.
|
Radarr V2 may work, but it is not supported please upgrade to V3 if you can.
|
||||||
|
|
||||||
|
Items in your List Exclusions will be ignored by PMM.
|
||||||
|
|
||||||
A `radarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `radarr` mapping individually per library.
|
A `radarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `radarr` mapping individually per library.
|
||||||
|
|
||||||
Below is a `radarr` mapping example and the full set of attributes:
|
Below is a `radarr` mapping example and the full set of attributes:
|
||||||
|
|
|
@ -4,6 +4,8 @@ Configuring [Sonarr](https://sonarr.tv/) is optional but will allow you to send
|
||||||
|
|
||||||
Sonarr V2 may work, but it is not supported please upgrade to V3 if you can.
|
Sonarr V2 may work, but it is not supported please upgrade to V3 if you can.
|
||||||
|
|
||||||
|
Items in your List Exclusions will be ignored by PMM.
|
||||||
|
|
||||||
A `sonarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `sonarr` mapping individually per library.
|
A `sonarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `sonarr` mapping individually per library.
|
||||||
|
|
||||||
Below is a `sonarr` mapping example and the full set of attributes:
|
Below is a `sonarr` mapping example and the full set of attributes:
|
||||||
|
|
|
@ -9,6 +9,7 @@ Below is a `trakt` mapping example and the full set of attributes:
|
||||||
trakt:
|
trakt:
|
||||||
client_id: ################################################################
|
client_id: ################################################################
|
||||||
client_secret: ################################################################
|
client_secret: ################################################################
|
||||||
|
pin:
|
||||||
authorization:
|
authorization:
|
||||||
access_token:
|
access_token:
|
||||||
token_type:
|
token_type:
|
||||||
|
@ -22,22 +23,17 @@ trakt:
|
||||||
|:----------------|:--------------------------------|:-------:|:--------:|
|
|:----------------|:--------------------------------|:-------:|:--------:|
|
||||||
| `client_id` | Trakt Application Client ID | N/A | ✅ |
|
| `client_id` | Trakt Application Client ID | N/A | ✅ |
|
||||||
| `client_secret` | Trakt Application Client Secret | N/A | ✅ |
|
| `client_secret` | Trakt Application Client Secret | N/A | ✅ |
|
||||||
|
| `pin` | Trakt Pin | None | ❌ |
|
||||||
|
|
||||||
* All other attributes will be filled in by the script.
|
* All other attributes will be filled in by the script.
|
||||||
|
|
||||||
* To connect to Trakt.tv you must create a Trakt application and supply the script the `client id` and `client secret` provided, please do the following:
|
* To connect to Trakt.tv you must create a Trakt application and supply the script the `client_id`, `client_secret`, and `pin` provided, please do the following:
|
||||||
1. [Click here to create a Trakt API application.](https://trakt.tv/oauth/applications/new)
|
1. [Click here to create a Trakt API application.](https://trakt.tv/oauth/applications/new)
|
||||||
2. Enter a `Name` for the application.
|
2. Enter a `Name` for the application.
|
||||||
3. Enter `urn:ietf:wg:oauth:2.0:oob` for `Redirect uri`.
|
3. Enter `urn:ietf:wg:oauth:2.0:oob` for `Redirect uri`.
|
||||||
4. Click the `SAVE APP` button.
|
4. Click the `SAVE APP` button.
|
||||||
5. Record the `Client ID` and `Client Secret`.
|
5. Record the `Client ID` and `Client Secret` as `client_id` and `client_secret` in your Configuration File.
|
||||||
|
6. Navigate to `https://trakt.tv/oauth/authorize?response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=<<CLIENT_ID>>` replacing `<<CLIENT_ID>>` with your Client ID.
|
||||||
|
7. Record the `PIN` as `pin` in your Configuration File.
|
||||||
|
|
||||||
* On the first run, the script will walk the user through the OAuth flow by producing a Trakt URL for the user to follow. Once authenticated at the Trakt URL, the user needs to return the code to the script. If the code is correct, the script will populate the `authorization` sub-attributes to use in subsequent runs.
|
* Run the script shortly after obtaining your pin I don't know if it expires at any point or not.
|
||||||
|
|
||||||
<h4>OAuth Flow using Docker</h4>
|
|
||||||
|
|
||||||
To authenticate Trakt the first time, you need run the container with the `-it` flags in order to walk through the OAuth flow mentioned above. Once you have the Trakt authentication data saved into the YAML, you'll be able to run the container normally.
|
|
||||||
|
|
||||||
<h4>OAuth Flow using unRAID Docker</h4>
|
|
||||||
|
|
||||||
Directions on how to authenticate Trakt on unRAID can be found on the [unRAID Walkthrough](../home/guides/unraid.md#advanced-installation-authenticating-trakt-or-myanimelist) page.
|
|
|
@ -430,6 +430,7 @@ class ConfigFile:
|
||||||
self.Trakt = Trakt(self, {
|
self.Trakt = Trakt(self, {
|
||||||
"client_id": check_for_attribute(self.data, "client_id", parent="trakt", throw=True),
|
"client_id": check_for_attribute(self.data, "client_id", parent="trakt", throw=True),
|
||||||
"client_secret": check_for_attribute(self.data, "client_secret", parent="trakt", throw=True),
|
"client_secret": check_for_attribute(self.data, "client_secret", parent="trakt", throw=True),
|
||||||
|
"pin": check_for_attribute(self.data, "pin", parent="trakt", default_is_none=True),
|
||||||
"config_path": self.config_path,
|
"config_path": self.config_path,
|
||||||
"authorization": self.data["trakt"]["authorization"] if "authorization" in self.data["trakt"] else None
|
"authorization": self.data["trakt"]["authorization"] if "authorization" in self.data["trakt"] else None
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,6 @@ from ruamel import yaml
|
||||||
logger = util.logger
|
logger = util.logger
|
||||||
|
|
||||||
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
||||||
redirect_uri_encoded = redirect_uri.replace(":", "%3A")
|
|
||||||
base_url = "https://api.trakt.tv"
|
base_url = "https://api.trakt.tv"
|
||||||
builders = [
|
builders = [
|
||||||
"trakt_collected_daily", "trakt_collected_weekly", "trakt_collected_monthly", "trakt_collected_yearly", "trakt_collected_all",
|
"trakt_collected_daily", "trakt_collected_weekly", "trakt_collected_monthly", "trakt_collected_yearly", "trakt_collected_all",
|
||||||
|
@ -33,6 +32,7 @@ class Trakt:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.client_id = params["client_id"]
|
self.client_id = params["client_id"]
|
||||||
self.client_secret = params["client_secret"]
|
self.client_secret = params["client_secret"]
|
||||||
|
self.pin = params["pin"]
|
||||||
self.config_path = params["config_path"]
|
self.config_path = params["config_path"]
|
||||||
self.authorization = params["authorization"]
|
self.authorization = params["authorization"]
|
||||||
logger.secret(self.client_secret)
|
logger.secret(self.client_secret)
|
||||||
|
@ -41,13 +41,16 @@ class Trakt:
|
||||||
self._authorization()
|
self._authorization()
|
||||||
|
|
||||||
def _authorization(self):
|
def _authorization(self):
|
||||||
url = f"https://trakt.tv/oauth/authorize?response_type=code&client_id={self.client_id}&redirect_uri={redirect_uri_encoded}"
|
if self.pin:
|
||||||
|
pin = self.pin
|
||||||
|
else:
|
||||||
|
url = f"https://trakt.tv/oauth/authorize?response_type=code&redirect_uri={redirect_uri}&client_id={self.client_id}"
|
||||||
logger.info(f"Navigate to: {url}")
|
logger.info(f"Navigate to: {url}")
|
||||||
logger.info("If you get an OAuth error your client_id or client_secret is invalid")
|
logger.info("If you get an OAuth error your client_id or client_secret is invalid")
|
||||||
webbrowser.open(url, new=2)
|
webbrowser.open(url, new=2)
|
||||||
try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip()
|
try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip()
|
||||||
except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.")
|
except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.")
|
||||||
if not pin: raise Failed("Trakt Error: No input Trakt pin required.")
|
if not pin: raise Failed("Trakt Error: Trakt pin required.")
|
||||||
json = {
|
json = {
|
||||||
"code": pin,
|
"code": pin,
|
||||||
"client_id": self.client_id,
|
"client_id": self.client_id,
|
||||||
|
@ -94,6 +97,7 @@ class Trakt:
|
||||||
if self.authorization != authorization and not self.config.read_only:
|
if self.authorization != authorization and not self.config.read_only:
|
||||||
yaml.YAML().allow_duplicate_keys = True
|
yaml.YAML().allow_duplicate_keys = True
|
||||||
config, ind, bsi = yaml.util.load_yaml_guess_indent(open(self.config_path))
|
config, ind, bsi = yaml.util.load_yaml_guess_indent(open(self.config_path))
|
||||||
|
config["trakt"]["pin"] = None
|
||||||
config["trakt"]["authorization"] = {
|
config["trakt"]["authorization"] = {
|
||||||
"access_token": authorization["access_token"],
|
"access_token": authorization["access_token"],
|
||||||
"token_type": authorization["token_type"],
|
"token_type": authorization["token_type"],
|
||||||
|
|
Loading…
Reference in a new issue