Skip to content

Commit

Permalink
Updated Townlong Yak support
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Jan 25, 2021
1 parent 1dd7c06 commit 59667cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
37 changes: 9 additions & 28 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self):
self.cfCache = {}
self.wowiCache = {}
self.tukuiCache = None
self.townlongyakCache = None
self.checksumCache = {}
self.scraper = cloudscraper.create_scraper()

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')):
Expand Down
26 changes: 15 additions & 11 deletions CB/TownlongYak.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import os
import io
import re
import zipfile
import requests
from . import retry, HEADERS


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
Expand All @@ -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.')
Expand Down
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
2 changes: 1 addition & 1 deletion CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59667cf

Please sign in to comment.