mirror of
https://github.com/xtream1101/humblebundle-downloader.git
synced 2025-02-02 03:52:41 +01:00
Merge branch 'use_cookiejar' of https://github.com/rytilahti/humblebundle-downloader into rytilahti-use_cookiejar
This commit is contained in:
commit
0d6a06f950
@ -6,6 +6,7 @@ import parsel
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
|
from http.cookiejar import MozillaCookieJar
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -42,9 +43,8 @@ class DownloadLibrary:
|
|||||||
self.update = update
|
self.update = update
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
with open(self.cookie_path, 'r') as f:
|
self.cookiejar = MozillaCookieJar(self.cookie_path)
|
||||||
self.account_cookies = f.read().strip()
|
self.cookiejar.load()
|
||||||
|
|
||||||
self.cache_data = self._load_cache_data(self.cache_file)
|
self.cache_data = self._load_cache_data(self.cache_file)
|
||||||
self.purchase_keys = self.purchase_keys if self.purchase_keys else self._get_purchase_keys() # noqa: E501
|
self.purchase_keys = self.purchase_keys if self.purchase_keys else self._get_purchase_keys() # noqa: E501
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class DownloadLibrary:
|
|||||||
'machine_name': machine_name,
|
'machine_name': machine_name,
|
||||||
'filename': web_name,
|
'filename': web_name,
|
||||||
},
|
},
|
||||||
headers={'cookie': self.account_cookies},
|
cookies=self.cookiejar,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Failed to get download url for trove product {title}"
|
logger.error("Failed to get download url for trove product {title}"
|
||||||
@ -163,7 +163,7 @@ class DownloadLibrary:
|
|||||||
trove_page_url = trove_base_url.format(idx=idx)
|
trove_page_url = trove_base_url.format(idx=idx)
|
||||||
try:
|
try:
|
||||||
trove_r = requests.get(trove_page_url,
|
trove_r = requests.get(trove_page_url,
|
||||||
headers={'cookie': self.account_cookies})
|
cookies=self.cookiejar)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Failed to get products from Humble Trove")
|
logger.error("Failed to get products from Humble Trove")
|
||||||
return []
|
return []
|
||||||
@ -182,7 +182,8 @@ class DownloadLibrary:
|
|||||||
order_url = 'https://www.humblebundle.com/api/v1/order/{order_id}?all_tpkds=true'.format(order_id=order_id) # noqa: E501
|
order_url = 'https://www.humblebundle.com/api/v1/order/{order_id}?all_tpkds=true'.format(order_id=order_id) # noqa: E501
|
||||||
try:
|
try:
|
||||||
order_r = requests.get(order_url,
|
order_r = requests.get(order_url,
|
||||||
headers={'cookie': self.account_cookies,
|
cookies=self.cookiejar,
|
||||||
|
headers={
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
'content-encoding': 'gzip',
|
'content-encoding': 'gzip',
|
||||||
})
|
})
|
||||||
@ -362,15 +363,17 @@ class DownloadLibrary:
|
|||||||
def _get_purchase_keys(self):
|
def _get_purchase_keys(self):
|
||||||
try:
|
try:
|
||||||
library_r = requests.get('https://www.humblebundle.com/home/library', # noqa: E501
|
library_r = requests.get('https://www.humblebundle.com/home/library', # noqa: E501
|
||||||
headers={'cookie': self.account_cookies})
|
cookies=self.cookiejar)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Failed to get list of purchases")
|
logger.error("Failed to get list of purchases")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
logger.debug("Library request: " + str(library_r))
|
logger.debug("Library request: " + str(library_r))
|
||||||
library_page = parsel.Selector(text=library_r.text)
|
library_page = parsel.Selector(text=library_r.text)
|
||||||
orders_json = json.loads(library_page.css('#user-home-json-data')
|
user_data = library_page.css('#user-home-json-data').xpath('string()').extract_first()
|
||||||
.xpath('string()').extract_first())
|
if user_data is None:
|
||||||
|
raise Exception("Unable to download user-data, cookies missing?")
|
||||||
|
orders_json = json.loads(user_data)
|
||||||
return orders_json['gamekeys']
|
return orders_json['gamekeys']
|
||||||
|
|
||||||
def _should_download_platform(self, platform):
|
def _should_download_platform(self, platform):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user