Refactor CurseForge provider to reuse logic from Web provider.

This commit is contained in:
Casper V. Kristensen 2019-10-10 00:08:57 +02:00
parent 0bfa0d2326
commit b07a55778f
Signed by: caspervk
GPG key ID: 289CA03790535054

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")