diff --git a/CB/Core.py b/CB/Core.py index b7512c5..6a69999 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -42,6 +42,7 @@ def __init__(self): self.cfCache = {} self.wowiCache = {} self.tukuiCache = None + self.townlongyakCache = None self.checksumCache = {} self.scraper = cloudscraper.create_scraper() @@ -203,11 +204,12 @@ def parse_url(self, url): elif url.startswith('https://github.com/'): return GitHubAddon(url, self.clientType) elif url.startswith('https://www.townlong-yak.com/addons/'): + self.bulk_townlongyak_check() if url in self.config['IgnoreClientVersion'].keys() or self.clientType == 'wow_retail': - clienttype = 0 + clienttype = 'retail' else: - clienttype = 1 - return TownlongYakAddon(url, clienttype) + clienttype = 'classic' + return TownlongYakAddon(url, self.townlongyakCache, clienttype) elif url.lower() == 'elvui': if self.clientType == 'wow_retail': return TukuiAddon('ElvUI', self.tukuiCache, 'elvui') @@ -602,32 +604,11 @@ def bulk_tukui_check(self): f'{"addons" if self.clientType == "wow_retail" else "classic-addons"}', headers=HEADERS, timeout=5).json() - """ @retry(custom_error='Failed to parse Townlong Yak API data') - def bulk_ty_check(self): - token = self.config['TYBundleToken'] - if token == '': - payload = requests.get('https://www.townlong-yak.com/addons/us/new', headers=HEADERS, timeout=5).json() - if payload['next']: - self.config['TYBundleToken'] = payload['next'] - self.save_config() - self.bulk_ty_check() - else: - raise RuntimeError - else: - payload = requests.get(f'https://www.townlong-yak.com/addons/us/{token}', headers=HEADERS, timeout=5).json() - if 'next' in payload: - for addon in payload['up']: - if addon['pi'] not in self.config['TYCache']: - self.config['TYCache'][addon['pi']] = {} - self.config['TYCache'][addon['pi']][addon['ch']] = {'Version': addon['fv'], - 'ChangeLog': addon['re'], - 'Link': addon['dl']} - self.config['TYBundleToken'] = payload['next'] - self.save_config() - if not payload['current']: - self.bulk_ty_check() - """ + def bulk_townlongyak_check(self): + if not self.townlongyakCache: + self.townlongyakCache = requests.get('https://hub.dev.wowup.io/addons/author/foxlit', + headers=HEADERS, timeout=5).json() def detect_accounts(self): if os.path.isdir(Path('WTF/Account')): diff --git a/CB/TownlongYak.py b/CB/TownlongYak.py index 863dacd..eeeb47e 100644 --- a/CB/TownlongYak.py +++ b/CB/TownlongYak.py @@ -1,6 +1,5 @@ import os import io -import re import zipfile import requests from . import retry, HEADERS @@ -8,12 +7,16 @@ class TownlongYakAddon: @retry() - def __init__(self, url, clienttype): + def __init__(self, url, checkcache, clienttype): + for addon in checkcache['addons']: + if addon['repository'] == url: + self.payload = addon + break + else: + raise RuntimeError(url) self.project = url.split('/')[-1] - self.payload = requests.get(f'https://www.townlong-yak.com/addons/api/install-bundle/{self.project}', - headers=HEADERS, timeout=5).json() - self.name = self.payload['name'].strip().strip('\u200b') - self.author = [self.payload['author']] + self.name = self.payload['repository_name'].strip().strip('\u200b') + self.author = [self.payload['owner_name']] self.clientType = clienttype self.uiVersion = None self.archive = None @@ -26,11 +29,12 @@ def __init__(self, url, clienttype): def get_current_version(self): for release in self.payload['releases']: - if release['ch'] == self.clientType: - self.downloadUrl = release['dl'] - self.currentVersion = re.findall(r'.*-(.*)\.zip$', release['dl'])[0] - self.changelogUrl = f'https://www.townlong-yak.com/addons/{self.project}/release/{self.currentVersion}' - self.uiVersion = release['cv'][0] + if release['game_type'] == self.clientType and not release['prerelease']: + self.downloadUrl = release['download_url'] + self.currentVersion = release['name'].replace(f'{self.project}-', '').\ + replace(f'{self.name.lower()}-', '') + self.changelogUrl = f'https://www.townlong-yak.com/addons/{self.project}' \ + f'/release/{self.currentVersion.replace("-", "")}' break else: raise RuntimeError(f'{self.name}.\nFailed to find release for your client version.') diff --git a/CB/__init__.py b/CB/__init__.py index 0f67780..c168baa 100644 --- a/CB/__init__.py +++ b/CB/__init__.py @@ -2,7 +2,7 @@ import random from rich.terminal_theme import TerminalTheme -__version__ = '3.17.0' +__version__ = '3.17.1' __license__ = 'GPLv3' __copyright__ = '2019-2020, Paweł Jastrzębski ' __docformat__ = 'restructuredtext en' diff --git a/CurseBreaker.py b/CurseBreaker.py index 1151659..e373c78 100644 --- a/CurseBreaker.py +++ b/CurseBreaker.py @@ -593,7 +593,7 @@ def c_orphans(self, _): orphansd, orphansf = self.core.find_orphans() self.console.print('[green]Directories that are not part of any installed addon:[/green]') for orphan in sorted(orphansd): - self.console.print(orphan.replace('[GIT]', '[yellow]\[GIT][/yellow]'), highlight=False) + self.console.print(orphan.replace('[GIT]', '[yellow][GIT][/yellow]'), highlight=False) self.console.print('\n[green]Files that are leftovers after no longer installed addons:[/green]') for orphan in sorted(orphansf): self.console.print(orphan, highlight=False)