2020-01-19 15:25:00 +01:00
|
|
|
import os
|
2021-05-21 15:17:47 +02:00
|
|
|
import sys
|
2020-01-19 15:25:00 +01:00
|
|
|
import logging
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
LOG_LEVEL = os.environ.get('HBD_LOGLEVEL', 'INFO').upper()
|
|
|
|
logging.basicConfig(
|
|
|
|
level=LOG_LEVEL,
|
|
|
|
format='%(message)s',
|
|
|
|
)
|
2020-01-26 16:19:08 +01:00
|
|
|
# Ignore unwanted logs from the requests lib when debuging
|
|
|
|
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)
|
2020-01-19 15:25:00 +01:00
|
|
|
|
|
|
|
|
2021-05-21 15:17:47 +02:00
|
|
|
def parse_args(args):
|
2021-11-20 11:07:39 +01:00
|
|
|
if len(args) > 0 and args[0].lower() == 'download':
|
2021-05-21 15:17:47 +02:00
|
|
|
args = args[1:]
|
|
|
|
raise DeprecationWarning("`download` argument is no longer used")
|
|
|
|
|
2020-01-19 15:25:00 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
2021-05-21 15:17:47 +02:00
|
|
|
cookie = parser.add_mutually_exclusive_group(required=True)
|
2021-02-14 15:51:40 +01:00
|
|
|
cookie.add_argument(
|
2020-01-19 15:40:41 +01:00
|
|
|
'-c', '--cookie-file', type=str,
|
2020-01-20 00:39:28 +01:00
|
|
|
help="Location of the cookies file",
|
2021-02-14 15:51:40 +01:00
|
|
|
)
|
|
|
|
cookie.add_argument(
|
|
|
|
'-s', '--session-auth', type=str,
|
|
|
|
help="Value of the cookie _simpleauth_sess. WRAP IN QUOTES",
|
2020-01-19 15:40:41 +01:00
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-19 15:40:41 +01:00
|
|
|
'-l', '--library-path', type=str,
|
|
|
|
help="Folder to download all content to",
|
|
|
|
required=True,
|
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-26 16:19:08 +01:00
|
|
|
'-t', '--trove', action='store_true',
|
|
|
|
help="Only check and download Humble Trove content",
|
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-26 16:19:08 +01:00
|
|
|
'-u', '--update', action='store_true',
|
|
|
|
help=("Check to see if products have been updated "
|
|
|
|
"(still get new products)"),
|
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-20 05:11:35 +01:00
|
|
|
'-p', '--platform',
|
|
|
|
type=str, nargs='*',
|
|
|
|
help=("Only get content in a platform. Values can be seen in your "
|
|
|
|
"humble bundle's library dropdown. Ex: -p ebook video"),
|
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-19 15:40:41 +01:00
|
|
|
'--progress',
|
|
|
|
action='store_true',
|
|
|
|
help="Display progress bar for downloads",
|
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
filter_ext = parser.add_mutually_exclusive_group()
|
2020-01-20 04:31:43 +01:00
|
|
|
filter_ext.add_argument(
|
|
|
|
'-e', '--exclude',
|
|
|
|
type=str, nargs='*',
|
2020-01-20 05:11:35 +01:00
|
|
|
help=("File extensions to ignore when downloading files. "
|
|
|
|
"Ex: -e pdf mobi"),
|
2020-01-20 04:31:43 +01:00
|
|
|
)
|
|
|
|
filter_ext.add_argument(
|
|
|
|
'-i', '--include',
|
|
|
|
type=str, nargs='*',
|
2020-01-20 05:11:35 +01:00
|
|
|
help="Only download files with these extensions. Ex: -i pdf mobi",
|
2020-01-20 04:31:43 +01:00
|
|
|
)
|
2021-05-21 15:17:47 +02:00
|
|
|
parser.add_argument(
|
2020-01-20 16:26:48 +01:00
|
|
|
'-k', '--keys',
|
|
|
|
type=str, nargs='*',
|
|
|
|
help=("The purchase download key. Find in the url on the "
|
|
|
|
"products/bundle download page. Can set multiple"),
|
|
|
|
)
|
2020-01-19 15:25:00 +01:00
|
|
|
|
2021-05-21 15:17:47 +02:00
|
|
|
return parser.parse_args(args)
|
|
|
|
|
|
|
|
|
|
|
|
def cli():
|
|
|
|
cli_args = parse_args(sys.argv[1:])
|
2020-01-19 15:25:00 +01:00
|
|
|
|
2021-05-21 15:17:47 +02:00
|
|
|
from .download_library import DownloadLibrary
|
|
|
|
DownloadLibrary(
|
|
|
|
cli_args.library_path,
|
|
|
|
cookie_path=cli_args.cookie_file,
|
|
|
|
cookie_auth=cli_args.session_auth,
|
|
|
|
progress_bar=cli_args.progress,
|
|
|
|
ext_include=cli_args.include,
|
|
|
|
ext_exclude=cli_args.exclude,
|
|
|
|
platform_include=cli_args.platform,
|
|
|
|
purchase_keys=cli_args.keys,
|
|
|
|
trove=cli_args.trove,
|
|
|
|
update=cli_args.update,
|
|
|
|
).start()
|