[122] git_assets

pull/1335/head
meisnate12 2 years ago
parent b22a7fc341
commit 5e4b39abf5

@ -1 +1 @@
1.18.3-develop121 1.18.3-develop122

@ -1,9 +1,11 @@
import re import re
from modules import util from modules import util
from modules.util import Failed
logger = util.logger logger = util.logger
base_url = "https://api.github.com/repos/meisnate12/Plex-Meta-Manager" base_url = "https://api.github.com"
pmm_base = f"{base_url}/repos/meisnate12/Plex-Meta-Manager"
configs_raw_url = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs" configs_raw_url = "https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager-Configs"
class GitHub: class GitHub:
@ -13,13 +15,29 @@ class GitHub:
self._configs_url = None self._configs_url = None
self._config_tags = [] self._config_tags = []
def get_top_tree(self, repo):
if not str(repo).startswith("/"):
repo = f"/{repo}"
if not str(repo).endswith("/"):
repo = f"{repo}/"
response = self.config.get(f"{base_url}/repos{repo}commits")
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
def get_tree(self, tree_url):
response = self.config.get(tree_url)
if response.status_code >= 400:
raise Failed(f"Git Error: No tree found at {tree_url}")
return {i["path"]: i for i in response.json()["tree"]}
def latest_release_notes(self): def latest_release_notes(self):
response = self.config.get_json(f"{base_url}/releases/latest") response = self.config.get_json(f"{pmm_base}/releases/latest")
return response["body"] return response["body"]
def get_commits(self, dev_version, nightly=False): def get_commits(self, dev_version, nightly=False):
master_sha = self.config.get_json(f"{base_url}/commits/master")["sha"] master_sha = self.config.get_json(f"{pmm_base}/commits/master")["sha"]
response = self.config.get_json(f"{base_url}/commits", params={"sha": "nightly" if nightly else "develop"}) response = self.config.get_json(f"{pmm_base}/commits", params={"sha": "nightly" if nightly else "develop"})
commits = [] commits = []
for commit in response: for commit in response:
if commit["sha"] == master_sha: if commit["sha"] == master_sha:
@ -35,7 +53,7 @@ class GitHub:
def config_tags(self): def config_tags(self):
if not self._config_tags: if not self._config_tags:
try: try:
self._config_tags = [r["ref"][11:] for r in self.config.get_json(f"{base_url}-Configs/git/refs/tags")] self._config_tags = [r["ref"][11:] for r in self.config.get_json(f"{pmm_base}-Configs/git/refs/tags")]
except TypeError: except TypeError:
pass pass
return self._config_tags return self._config_tags

@ -665,7 +665,7 @@ class MetadataFile(DataFile):
raise Failed("Image Set Error: style file call attribute is not a dictionary") raise Failed("Image Set Error: style file call attribute is not a dictionary")
elif not set_dict: elif not set_dict:
raise Failed("Image Set Error: style file call attribute dictionary is empty") raise Failed("Image Set Error: style file call attribute dictionary is empty")
image_set_data = self.get_image_set(set_dict, set_key) image_set_data = self.get_image_set(set_dict, set_key, asset_data=set_data)
meta_data["image_set"] = image_set meta_data["image_set"] = image_set
meta_data["set"] = set_key meta_data["set"] = set_key
if item_name in image_set_data and isinstance(image_set_data[item_name], dict) and "seasons" in image_set_data[item_name] and image_set_data[item_name]["seasons"]: if item_name in image_set_data and isinstance(image_set_data[item_name], dict) and "seasons" in image_set_data[item_name] and image_set_data[item_name]["seasons"]:
@ -1151,13 +1151,103 @@ class MetadataFile(DataFile):
logger.info("") logger.info("")
logger.info(f"Metadata File Loaded Successfully") logger.info(f"Metadata File Loaded Successfully")
def get_image_set(self, set_data, set_name): def get_image_set(self, set_data, set_name, asset_data=None):
set_id = "" set_id = ""
for k, v in set_data.items(): for k, v in set_data.items():
set_id = f"{k}: {v}" set_id = f"{k}: {v}"
break break
if set_id in self.library.image_sets: if set_id not in self.library.image_sets and "git_assets" in set_data:
return self.library.image_sets[set_id] if not set_data["git_assets"]:
raise Failed("Image Set Error: git_assets cannot be blank")
if not asset_data:
raise Failed("Image Set Error: asset_data cannot be blank")
top_tree, repo = self.config.GitHub.get_top_tree(set_data["git_assets"])
sub = set_data["git_subfolder"] if "git_subfolder" in set_data and set_data["git_subfolder"] else ""
sub = sub.replace("\\", "/")
if sub.startswith("/"):
sub = sub[1:]
if sub.endswith("/"):
sub = sub[:-1]
if sub:
sub_str = ""
for folder in sub.split("/"):
sub_str += f"{folder}/"
if folder not in top_tree:
raise Failed(f"Image Set Error: Subfolder {folder} Not Found at https://github.com{repo}tree/master/{sub_str}")
top_tree = self.config.GitHub.get_tree(top_tree[folder]["url"])
sub = f"{sub}/"
def repo_url(u):
return f"https://raw.githubusercontent.com{repo}master/{sub}{u}"
def from_repo(u):
return self.config.get(repo_url(u)).content.decode().strip()
def check_for_definition(check_key, check_tree, is_poster=True, git_name=None):
attr_name = "poster" if is_poster else "background"
if (git_name and git_name.lower().endswith(".tpdb")) or (not git_name and f"{attr_name}.tpdb" in check_tree):
return f"tpdb_{attr_name}", from_repo(f"{check_key}/{git_name if git_name else f'{attr_name}.tpdb'}")
elif (git_name and git_name.lower().endswith(".url")) or (not git_name and f"{attr_name}.url" in check_tree):
return f"url_{attr_name}", from_repo(f"{check_key}/{git_name if git_name else f'{attr_name}.url'}")
elif git_name:
if git_name in check_tree:
return f"url_{attr_name}", repo_url(f"{check_key}/{git_name}")
else:
for ct in check_tree:
if ct.startswith(attr_name):
return f"url_{attr_name}", repo_url(f"{check_key}/{ct}")
return None, None
def init_set(check_key, check_tree, git_name=None):
_data = {}
attr, attr_data = check_for_definition(check_key, check_tree, git_name=git_name)
if attr:
_data[attr] = attr_data
attr, attr_data = check_for_definition(check_key, check_tree, is_poster=False, git_name=git_name)
if attr:
_data[attr] = attr_data
return _data
image_sets = {}
for k in asset_data:
if k in ["styles", "collections"]:
continue
if k not in top_tree:
logger.info(f"Image Set Warning: {k} not found at https://github.com{repo}tree/master/{sub}")
continue
item_folder = self.config.GitHub.get_tree(top_tree[k]["url"])
item_data = init_set(k, item_folder)
seasons = {}
for ik in item_folder:
match = re.search(r"(\d+)", ik)
if match:
season_num = int(match.group(1))
season_folder = self.config.GitHub.get_tree(item_folder[ik]["url"])
season_data = init_set(f"{k}/{ik}", season_folder)
episodes = {}
for sk in season_folder:
match = re.search(r"(\d+)(?!.*\d)", sk)
if match:
episode_num = int(match.group(1))
episodes[episode_num] = init_set(f"{k}/{ik}", season_folder, git_name=sk)
if episodes:
season_data["episodes"] = episodes
seasons[season_num] = season_data
if seasons:
item_data["seasons"] = seasons
image_sets[k] = item_data
self.library.image_sets[set_id] = image_sets
if set_name and set_name in self.set_collections and "collections" in top_tree:
collections_folder = self.config.GitHub.get_tree(top_tree["collections"]["url"])
for k, alts in self.set_collections[set_name].items():
if k in collections_folder:
collection_data = init_set(f"collections/{k}", self.config.GitHub.get_tree(collections_folder[k]["url"]))
self.library.collection_images[k] = collection_data
for alt in alts:
self.library.collection_images[alt] = collection_data
elif set_id not in self.library.image_sets:
files = util.load_files(set_data, "image_set", err_type=self.type_str, single=True) files = util.load_files(set_data, "image_set", err_type=self.type_str, single=True)
if not files: if not files:
raise Failed(f"{self.type_str} Error: No Path Found for image_set") raise Failed(f"{self.type_str} Error: No Path Found for image_set")

Loading…
Cancel
Save