Compare commits

...

2 commits

Author SHA1 Message Date
Casper V. Kristensen b07a55778f
Refactor CurseForge provider to reuse logic from Web provider. 2019-10-10 00:08:57 +02:00
Casper V. Kristensen 0bfa0d2326
Add support for GitHub releases. 2019-10-10 00:08:06 +02:00
4 changed files with 39 additions and 21 deletions

View file

@ -35,7 +35,9 @@ For more information, see <https://git.caspervk.net/caspervk/wau>.
- CurseForge.com
- WowInterface.com
- Git
- ~~GitHub Releases~~ (coming soon™)
- Supports `<url>#<branch>` syntax.
- GitHub Releases
- `https://github.com/x/y/releases`.
- HTTP

View file

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

View file

@ -1,13 +1,13 @@
import logging
from .base import Provider
from .web import Web
from .. import http
from ..addons import Addon
logger = logging.getLogger(__name__)
class CurseForge(Provider):
class CurseForge(Web):
api_url = "https://addons-ecs.forgesvc.net"
@classmethod
@ -15,21 +15,12 @@ class CurseForge(Provider):
return "curseforge.com/wow/addons/" in url
@classmethod
def download(cls, addon: Addon) -> bool:
def download(cls, addon: Addon, url: str = None) -> bool:
"""
Twitch API from: https://github.com/Gaz492/TwitchAPI. Thanks Gareth! <3
"""
latest_file_url = cls._get_latest_file_url(addon)
try:
if addon.is_cached() and latest_file_url == addon.provider_data["file_url"]:
return False
except KeyError:
pass
addon.create_download_dir(recreate=True) # clean download dir
http.download_zip(latest_file_url, addon.download_dir)
addon.provider_data["file_url"] = latest_file_url
return True
return super().download(addon, url=latest_file_url)
@classmethod
def _get_curse_id(cls, addon: Addon) -> int:
@ -72,4 +63,4 @@ class CurseForge(Provider):
for file in info["latestFiles"]:
if file["gameVersionFlavor"] == "wow_classic" and file["releaseType"] == 1: # 1: release, 2: beta, 3: alpha
return file["downloadUrl"]
raise ValueError("No file found")
raise FileNotFoundError("No file found")

View file

@ -1,13 +1,38 @@
import logging
import re
from typing import Tuple
from .web import Web
from .. import http
from ..addons import Addon
logger = logging.getLogger(__name__)
class GitHub(Web):
api_url = "https://api.github.com"
class Provider:
@classmethod
def is_supported(cls, url: str) -> bool:
return bool(re.search("github.com/.*/.*/releases", url, flags=re.IGNORECASE))
try:
cls._parse_url(url)
return True
except AttributeError:
return False
@classmethod
def download(cls, addon: Addon) -> bool:
raise NotImplemented
def download(cls, addon: Addon, url: str = None) -> bool:
repo_owner, repo_name = cls._parse_url(addon.url)
addon.name = repo_name
latest_release = http.open(
url=f"{cls.api_url}/repos/{repo_owner}/{repo_name}/releases/latest"
).json()
for asset in latest_release["assets"]:
if asset["content_type"] == "application/x-zip-compressed":
return super().download(addon, asset["browser_download_url"])
raise FileNotFoundError("No zip file found for latest release")
@classmethod
def _parse_url(cls, url: str) -> Tuple[str, str]:
repo_owner, repo_name = re.search(r"github.com/(.+)/(.+)/releases", url).groups()
return repo_owner, repo_name