Skip to content

Commit

Permalink
Tweaked cloudscraper usage
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Feb 1, 2020
1 parent 2cc7478 commit d0676b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self):
self.cfDirs = None
self.cfCache = {}
self.wowiCache = {}
self.scraper = cloudscraper.create_scraper()

def init_config(self):
if os.path.isfile('CurseBreaker.json'):
Expand Down Expand Up @@ -125,9 +126,9 @@ def parse_url(self, url):
if url.startswith('https://www.curseforge.com/wow/addons/'):
return CurseForgeAddon(self.parse_cf_id(url), self.cfCache,
'wow' if url in self.config['IgnoreClientVersion'].keys() else self.clientType,
self.check_if_dev(url))
self.check_if_dev(url), self.scraper)
elif url.startswith('https://www.wowinterface.com/downloads/'):
return WoWInterfaceAddon(url, self.wowiCache)
return WoWInterfaceAddon(url, self.wowiCache, self.scraper)
elif url.startswith('https://www.tukui.org/addons.php?id='):
if self.clientType == 'wow_classic':
raise RuntimeError('Incorrect client version.')
Expand Down Expand Up @@ -340,8 +341,7 @@ def parse_cf_id(self, url):
if slug in self.cfIDs:
project = self.cfIDs[slug]
else:
scraper = cloudscraper.create_scraper()
payload = scraper.get(url + '/download-client')
payload = self.scraper.get(url + '/download-client')
if payload.status_code == 404:
raise RuntimeError(slug)
xml = parseString(payload.text)
Expand Down
5 changes: 2 additions & 3 deletions CB/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import io
import zipfile
import requests
import cloudscraper
from . import retry, HEADERS
from operator import itemgetter


class CurseForgeAddon:
@retry()
def __init__(self, project, checkcache, clienttype, allowdev):
def __init__(self, project, checkcache, clienttype, allowdev, scraper):
if project in checkcache:
self.payload = checkcache[project]
else:
Expand All @@ -24,11 +23,11 @@ def __init__(self, project, checkcache, clienttype, allowdev):
raise RuntimeError(f'{self.name}.\nThe project doesn\'t have any releases.')
self.clientType = clienttype
self.allowDev = allowdev
self.scraper = scraper
self.downloadUrl = None
self.currentVersion = None
self.archive = None
self.directories = []
self.scraper = cloudscraper.create_scraper()
self.get_current_version()

def get_current_version(self):
Expand Down
5 changes: 2 additions & 3 deletions CB/WoWInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import re
import zipfile
import requests
import cloudscraper
from . import retry, HEADERS


class WoWInterfaceAddon:
@retry()
def __init__(self, url, checkcache):
def __init__(self, url, checkcache, scraper):
project = re.findall(r'\d+', url)[0]
if project in checkcache:
self.payload = checkcache[project]
Expand All @@ -25,7 +24,7 @@ def __init__(self, url, checkcache):
self.currentVersion = self.payload['UIVersion']
self.archive = None
self.directories = []
self.scraper = cloudscraper.create_scraper()
self.scraper = scraper

@retry()
def get_addon(self):
Expand Down

0 comments on commit d0676b6

Please sign in to comment.