Add TukUI AddOn provider

This commit is contained in:
Casper V. Kristensen 2022-09-20 23:07:40 +02:00
parent d2c7c020ab
commit 0086cb798c
2 changed files with 32 additions and 0 deletions

View file

@ -2,6 +2,7 @@ from .base import Provider
from .curseforge import CurseForge from .curseforge import CurseForge
from .git import Git from .git import Git
from .github import GitHub from .github import GitHub
from .tukui import TukUI
from .web import Web from .web import Web
from .wowinterface import WowInterface from .wowinterface import WowInterface
@ -9,6 +10,7 @@ from .wowinterface import WowInterface
PROVIDERS = { # in order of preference PROVIDERS = { # in order of preference
"curse": CurseForge, "curse": CurseForge,
"wowinterface": WowInterface, "wowinterface": WowInterface,
"tukui": TukUI,
"github": GitHub, "github": GitHub,
"git": Git, "git": Git,
"web": Web "web": Web

30
wau/providers/tukui.py Executable file
View file

@ -0,0 +1,30 @@
import logging
from .web import Web
from .. import http
from ..addons import Addon
logger = logging.getLogger(__name__)
class TukUI(Web):
api_url = "https://www.tukui.org/api.php?classic-wotlk-addons"
@classmethod
def is_supported(cls, url: str) -> bool:
return "tukui.org" in url
@classmethod
def download(cls, addon: Addon, url: str = None) -> bool:
file_url = cls._get_file_url(addon)
return super().download(addon, url=file_url)
@classmethod
def _get_file_url(self, addon: Addon) -> str:
logger.debug("Getting all AddOns info from TukUI")
# Find the given AddOn URL in the list of all TukUI AddOns
tukui_addons = http.open(self.api_url).json()
for tukui_addon in tukui_addons:
if tukui_addon["web_url"] == addon.url:
return tukui_addon["url"]
raise ValueError("AddOn not found in TukUI AddOns.")