Skip to content

Commit

Permalink
Added WoWInterface support
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Mar 9, 2019
1 parent 115963c commit 1f5ceca
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class GUI:
def __init__(self):
parser = argparse.ArgumentParser(description='All options support comma separated lists. '
'When started without arguments program will update all add-ons.',
epilog='Supported URLs: https://www.curseforge.com/wow/addons/<addon_name>,'
' ElvUI, ElvUI:Dev')
epilog='Supported URLs: https://www.curseforge.com/wow/addons/<addon_name>, '
'https://www.wowinterface.com/downloads/<addon_name>, ElvUI, ElvUI:Dev')
parser.add_argument('-a', '--add', help='Install add-ons', metavar='URL')
parser.add_argument('-r', '--remove', help='Remove add-ons', metavar='URL')
parser.add_argument('-u', '--update', help='Update add-ons', metavar='URL')
Expand Down
3 changes: 3 additions & 0 deletions CurseBreaker/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
from .CurseForge import CurseForgeAddon
from .ElvUI import ElvUIAddon
from .WoWInterface import WoWInterfaceAddon


class Core:
Expand Down Expand Up @@ -37,6 +38,8 @@ def parse_url(self, url):
if hasattr(parser, 'redirectUrl'):
self.config['URLCache'][url] = parser.redirectUrl
return parser
if url.startswith('https://www.wowinterface.com/downloads/'):
return WoWInterfaceAddon(url)
elif url.lower() == 'elvui':
return ElvUIAddon('master')
elif url.lower() == 'elvui:dev':
Expand Down
4 changes: 2 additions & 2 deletions CurseBreaker/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def get_current_version(self):
if not self.currentVersion:
for row in table.find_all('tr', attrs={'class': 'project-file-list-item'}):
if 'Beta' in str(row.find('td', attrs={'class': 'project-file-release-type'})):
self.currentVersion = row.find('a', attrs={'class': 'overflow-tip twitch-link'}).contents[
0].strip()
self.currentVersion = row.find('a', attrs={'class': 'overflow-tip twitch-link'}).contents[0]\
.strip()
break
except Exception:
raise RuntimeError('Failed to parse CurseForge page. Check if URL is correct.')
Expand Down
40 changes: 40 additions & 0 deletions CurseBreaker/WoWInterface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import io
import zipfile
import requests
from bs4 import BeautifulSoup


class WoWInterfaceAddon:
def __init__(self, url):
try:
self.soup = BeautifulSoup(requests.get(url).content, 'html.parser')
self.name = self.soup.find('meta', attrs={'property': 'og:title'})['content']
self.downloadUrl = url.replace('/info', '/download')
self.currentVersion = None
self.archive = None
self.directories = []
except Exception:
raise RuntimeError('Failed to parse WoWInterface page. Check if URL is correct.')

def get_current_version(self):
try:
self.currentVersion = self.soup.find('div', attrs={'id': 'version'}).contents[0].split(': ')[1].strip()
except Exception:
raise RuntimeError('Failed to parse WoWInterface page. Check if URL is correct.')

def get_addon(self):
try:
dsoup = BeautifulSoup(requests.get(self.downloadUrl).content, 'html.parser')
self.archive = zipfile.ZipFile(io.BytesIO(requests.get(dsoup.find('div', attrs={'class': 'manuallink'}).
find('a')['href'].strip()).content))
for file in self.archive.namelist():
if '/' not in os.path.dirname(file):
self.directories.append(os.path.dirname(file))
self.directories = list(set(self.directories))
except Exception:
raise RuntimeError('Failed to download the archive.')

def install(self, path):
self.get_addon()
self.archive.extractall(path)

0 comments on commit 1f5ceca

Please sign in to comment.