diff --git a/config/config.yml.template b/config/config.yml.template index 0cb4a397..6a2d0e38 100644 --- a/config/config.yml.template +++ b/config/config.yml.template @@ -89,6 +89,8 @@ tmdb: # REQUIRED for the script to run tautulli: # Can be individually specified per library as well url: http://192.168.1.12:8181 apikey: ################################ +github: + token: ################################ omdb: apikey: ######## cache_expiration: 60 diff --git a/docs/conf.py b/docs/conf.py index e54eff13..fac50ef8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -209,6 +209,7 @@ html_theme_options = { ("Trakt", "config/trakt"), ("MdbList", "config/mdblist"), ("OMDb", "config/omdb"), + ("Github", "config/github"), ("AniDB", "config/anidb"), ("MyAnimeList", "config/myanimelist"), ]), diff --git a/docs/config/configuration.md b/docs/config/configuration.md index 73f97eb7..b6a9b04b 100644 --- a/docs/config/configuration.md +++ b/docs/config/configuration.md @@ -16,6 +16,7 @@ This table outlines the third-party services that Plex Meta Manager can make use | [`webhooks`](webhooks) | ❌ | | [`plex`](plex) | ✅
Either here or per library | | [`tmdb`](tmdb) | ✅ | +| [`github`](github) | ❌ | | [`tautulli`](tautulli) | ❌ | | [`omdb`](omdb) | ❌ | | [`notifiarr`](notifiarr) | ❌ | diff --git a/docs/config/github.md b/docs/config/github.md new file mode 100644 index 00000000..db0bdf69 --- /dev/null +++ b/docs/config/github.md @@ -0,0 +1,19 @@ +# Github Attributes + +Configuring [Github](https://github.com/) is optional but can allow you to avoid rate limits when requesting data from github. + +Requests made with a github token have a higher rate limit than anonymous requests. + +A `github` mapping is in the root of the config file. + +Below is a `github` mapping example and the full set of attributes: +```yaml +github: + token: ################################ +``` + +| Attribute | Allowed Values | Default | Required | +|:-------------------|:---------------------------------------------------------------------------|:--------|:--------:| +| `token` | Github Personal Access Token | N/A | ✅ | + +* The Github Personal Access Token can be generated [here](https://github.com/settings/tokens). diff --git a/modules/config.py b/modules/config.py index 8b12e638..2d2a4a9a 100644 --- a/modules/config.py +++ b/modules/config.py @@ -262,6 +262,7 @@ class ConfigFile: hooks("collection_changes") temp["changes"] = None if not changes else changes if len(changes) > 1 else changes[0] self.data["webhooks"] = temp + if "github" in self.data: self.data["github"] = self.data.pop("github") if "plex" in self.data: self.data["plex"] = self.data.pop("plex") if "tmdb" in self.data: self.data["tmdb"] = self.data.pop("tmdb") if "tautulli" in self.data: self.data["tautulli"] = self.data.pop("tautulli") diff --git a/modules/github.py b/modules/github.py index bcd9afad..fd0a0267 100644 --- a/modules/github.py +++ b/modules/github.py @@ -12,6 +12,12 @@ configs_raw_url = f"{raw_url}/meisnate12/Plex-Meta-Manager-Configs" class GitHub: def __init__(self, config): self.config = config + self.headers = None + try: + self.token = config.data["github"]["token"] + self.headers = {'Authorization': 'token ' + self.token} + except: + self.token = None self.images_raw_url = f"{raw_url}/meisnate12/PMM-Image-Sets/master/sets/" self.translation_url = f"{raw_url}/meisnate12/PMM-Translations/master/defaults/" self._configs_url = None @@ -24,7 +30,7 @@ class GitHub: repo = f"/{repo}" if not str(repo).endswith("/"): repo = f"{repo}/" - response = self.config.get(f"{base_url}/repos{repo}commits") + response = self.config.get(f"{base_url}/repos{repo}commits", headers=self.headers) if response.status_code >= 400: raise Failed(f"Git Error: No repo found at https://github.com{repo}") return self.get_tree(response.json()[0]["commit"]["tree"]["url"]), repo @@ -36,12 +42,12 @@ class GitHub: return {i["path"]: i for i in response.json()["tree"]} def latest_release_notes(self): - response = self.config.get_json(f"{pmm_base}/releases/latest") + response = self.config.get_json(f"{pmm_base}/releases/latest", headers=self.headers) return response["body"] def get_commits(self, dev_version, nightly=False): - master_sha = self.config.get_json(f"{pmm_base}/commits/master")["sha"] - response = self.config.get_json(f"{pmm_base}/commits", params={"sha": "nightly" if nightly else "develop"}) + master_sha = self.config.get_json(f"{pmm_base}/commits/master", headers=self.headers)["sha"] + response = self.config.get_json(f"{pmm_base}/commits", headers=self.headers, params={"sha": "nightly" if nightly else "develop"}) commits = [] for commit in response: if commit["sha"] == master_sha: @@ -57,7 +63,7 @@ class GitHub: def config_tags(self): if not self._config_tags: try: - self._config_tags = [r["ref"][11:] for r in self.config.get_json(f"{pmm_base}-Configs/git/refs/tags")] + self._config_tags = [r["ref"][11:] for r in self.config.get_json(f"{pmm_base}-Configs/git/refs/tags", headers=self.headers)] except TypeError: pass return self._config_tags @@ -83,7 +89,7 @@ class GitHub: def translation_yaml(self, translation_key): if translation_key not in self._translations: url = f"{self.translation_url}{translation_key}.yml" - yaml = util.YAML(input_data=self.config.get(url).content).data + yaml = util.YAML(input_data=self.config.get(url, headers=self.headers).content).data output = {"collections": {}, "key_names": {}, "variables": {}} for k in output: if k in yaml: