Refactor CurseForge provider to reuse logic from Web provider.
This commit is contained in:
parent
0bfa0d2326
commit
b07a55778f
|
@ -1,13 +1,13 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .base import Provider
|
from .web import Web
|
||||||
from .. import http
|
from .. import http
|
||||||
from ..addons import Addon
|
from ..addons import Addon
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CurseForge(Provider):
|
class CurseForge(Web):
|
||||||
api_url = "https://addons-ecs.forgesvc.net"
|
api_url = "https://addons-ecs.forgesvc.net"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -15,21 +15,12 @@ class CurseForge(Provider):
|
||||||
return "curseforge.com/wow/addons/" in url
|
return "curseforge.com/wow/addons/" in url
|
||||||
|
|
||||||
@classmethod
|
@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
|
Twitch API from: https://github.com/Gaz492/TwitchAPI. Thanks Gareth! <3
|
||||||
"""
|
"""
|
||||||
latest_file_url = cls._get_latest_file_url(addon)
|
latest_file_url = cls._get_latest_file_url(addon)
|
||||||
try:
|
return super().download(addon, url=latest_file_url)
|
||||||
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
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_curse_id(cls, addon: Addon) -> int:
|
def _get_curse_id(cls, addon: Addon) -> int:
|
||||||
|
@ -72,4 +63,4 @@ class CurseForge(Provider):
|
||||||
for file in info["latestFiles"]:
|
for file in info["latestFiles"]:
|
||||||
if file["gameVersionFlavor"] == "wow_classic" and file["releaseType"] == 1: # 1: release, 2: beta, 3: alpha
|
if file["gameVersionFlavor"] == "wow_classic" and file["releaseType"] == 1: # 1: release, 2: beta, 3: alpha
|
||||||
return file["downloadUrl"]
|
return file["downloadUrl"]
|
||||||
raise ValueError("No file found")
|
raise FileNotFoundError("No file found")
|
||||||
|
|
Loading…
Reference in a new issue