forked from Mirrors/humblebundle-downloader
Entferne rebuild-cache da es Konflikte gibt
This commit is contained in:
6
cli.py
6
cli.py
@@ -93,11 +93,6 @@ def parse_args(args):
|
|||||||
"products/bundle download page. Can set multiple"
|
"products/bundle download page. Can set multiple"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--rebuild-cache",
|
|
||||||
action="store_true",
|
|
||||||
help="Rebuild cache by checking all existing files in library",
|
|
||||||
)
|
|
||||||
|
|
||||||
return parser.parse_args(args)
|
return parser.parse_args(args)
|
||||||
|
|
||||||
@@ -118,5 +113,4 @@ def cli():
|
|||||||
purchase_keys=cli_args.keys,
|
purchase_keys=cli_args.keys,
|
||||||
trove=cli_args.trove,
|
trove=cli_args.trove,
|
||||||
update=cli_args.update,
|
update=cli_args.update,
|
||||||
rebuild_cache=cli_args.rebuild_cache,
|
|
||||||
).start()
|
).start()
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class DownloadLibrary:
|
|||||||
purchase_keys=None,
|
purchase_keys=None,
|
||||||
trove=False,
|
trove=False,
|
||||||
update=False,
|
update=False,
|
||||||
rebuild_cache=False,
|
|
||||||
):
|
):
|
||||||
self.library_path = library_path
|
self.library_path = library_path
|
||||||
self.progress_bar = progress_bar
|
self.progress_bar = progress_bar
|
||||||
@@ -53,7 +52,6 @@ class DownloadLibrary:
|
|||||||
self.purchase_keys = purchase_keys
|
self.purchase_keys = purchase_keys
|
||||||
self.trove = trove
|
self.trove = trove
|
||||||
self.update = update
|
self.update = update
|
||||||
self.rebuild_cache = rebuild_cache
|
|
||||||
|
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
if cookie_path:
|
if cookie_path:
|
||||||
@@ -73,12 +71,6 @@ class DownloadLibrary:
|
|||||||
def start(self):
|
def start(self):
|
||||||
self.cache_file = os.path.join(self.library_path, ".cache.json")
|
self.cache_file = os.path.join(self.library_path, ".cache.json")
|
||||||
self.cache_data = self._load_cache_data(self.cache_file)
|
self.cache_data = self._load_cache_data(self.cache_file)
|
||||||
|
|
||||||
# If rebuild_cache is requested, clear the cache
|
|
||||||
if self.rebuild_cache:
|
|
||||||
logger.warning("Rebuilding cache from existing files...")
|
|
||||||
self.cache_data = {}
|
|
||||||
|
|
||||||
self.purchase_keys = (
|
self.purchase_keys = (
|
||||||
self.purchase_keys if self.purchase_keys else self._get_purchase_keys()
|
self.purchase_keys if self.purchase_keys else self._get_purchase_keys()
|
||||||
)
|
)
|
||||||
@@ -150,31 +142,19 @@ class DownloadLibrary:
|
|||||||
# Do not care about checking for updates at this time
|
# Do not care about checking for updates at this time
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Determine file paths
|
|
||||||
product_folder = os.path.join(self.library_path, "Humble Trove", title)
|
|
||||||
local_filename = os.path.join(product_folder, web_name)
|
|
||||||
|
|
||||||
# If no cache entry exists, check if file physically exists
|
|
||||||
if cache_file_info == {}:
|
|
||||||
existing_file_mtime = self._file_exists_in_library(local_filename)
|
|
||||||
if existing_file_mtime is not None and self.update is not True:
|
|
||||||
logger.info(
|
|
||||||
"Trove file exists but not in cache, adding to cache: {filename}".format(
|
|
||||||
filename=web_name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# Add to cache with current file info
|
|
||||||
self._update_cache_data(cache_file_key, file_info)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if file_info["uploaded_at"] != cache_file_info.get(
|
if file_info["uploaded_at"] != cache_file_info.get(
|
||||||
"uploaded_at"
|
"uploaded_at"
|
||||||
) and file_info["md5"] != cache_file_info.get("md5"):
|
) and file_info["md5"] != cache_file_info.get("md5"):
|
||||||
|
product_folder = os.path.join(self.library_path, "Humble Trove", title)
|
||||||
# Create directory to save the files to
|
# Create directory to save the files to
|
||||||
try:
|
try:
|
||||||
os.makedirs(product_folder)
|
os.makedirs(product_folder)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
local_filename = os.path.join(
|
||||||
|
product_folder,
|
||||||
|
web_name,
|
||||||
|
)
|
||||||
signed_url = self._get_trove_download_url(
|
signed_url = self._get_trove_download_url(
|
||||||
download["machine_name"],
|
download["machine_name"],
|
||||||
web_name,
|
web_name,
|
||||||
@@ -472,21 +452,6 @@ class DownloadLibrary:
|
|||||||
# Do not care about checking for updates at this time
|
# Do not care about checking for updates at this time
|
||||||
raise FileExistsError
|
raise FileExistsError
|
||||||
|
|
||||||
# If no cache entry exists, check if file physically exists
|
|
||||||
local_file = os.path.join(local_folder, local_filename)
|
|
||||||
if cache_file_info == {}:
|
|
||||||
existing_file_mtime = self._file_exists_in_library(local_file)
|
|
||||||
if existing_file_mtime is not None and self.update is not True:
|
|
||||||
logger.info(
|
|
||||||
"File exists but not in cache, adding to cache: {filename}".format(
|
|
||||||
filename=local_filename
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# Add to cache with file modification time
|
|
||||||
file_info = {"url_last_modified": existing_file_mtime}
|
|
||||||
self._update_cache_data(cache_file_key, file_info)
|
|
||||||
raise FileExistsError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote_file_r = self.session.get(remote_file, stream=True)
|
remote_file_r = self.session.get(remote_file, stream=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -635,16 +600,6 @@ class DownloadLibrary:
|
|||||||
|
|
||||||
return cache_data
|
return cache_data
|
||||||
|
|
||||||
def _file_exists_in_library(self, local_file):
|
|
||||||
"""
|
|
||||||
Check if a file exists in the library and return its modification time
|
|
||||||
formatted as HTTP Last-Modified header if it does.
|
|
||||||
"""
|
|
||||||
if os.path.isfile(local_file):
|
|
||||||
mtime = os.path.getmtime(local_file)
|
|
||||||
return time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(mtime))
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _get_purchase_keys(self):
|
def _get_purchase_keys(self):
|
||||||
try:
|
try:
|
||||||
library_r = self.session.get("https://www.humblebundle.com/home/library")
|
library_r = self.session.get("https://www.humblebundle.com/home/library")
|
||||||
|
|||||||
@@ -102,11 +102,6 @@ def parse_args(args):
|
|||||||
"products/bundle download page. Can set multiple"
|
"products/bundle download page. Can set multiple"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--rebuild-cache",
|
|
||||||
action="store_true",
|
|
||||||
help="Rebuild cache by checking all existing files in library",
|
|
||||||
)
|
|
||||||
|
|
||||||
return parser.parse_args(args)
|
return parser.parse_args(args)
|
||||||
|
|
||||||
@@ -127,7 +122,6 @@ def main():
|
|||||||
purchase_keys=cli_args.keys,
|
purchase_keys=cli_args.keys,
|
||||||
trove=cli_args.trove,
|
trove=cli_args.trove,
|
||||||
update=cli_args.update,
|
update=cli_args.update,
|
||||||
rebuild_cache=cli_args.rebuild_cache,
|
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user