2020-01-19 15:25:00 +01:00
|
|
|
import os
|
|
|
|
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',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def cli():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
subparsers = parser.add_subparsers(dest='action')
|
|
|
|
subparsers.required = True
|
|
|
|
|
|
|
|
###
|
|
|
|
# Generate cookie
|
|
|
|
###
|
2020-01-19 15:40:41 +01:00
|
|
|
parser_gencookie = subparsers.add_parser(
|
2020-01-19 16:00:40 +01:00
|
|
|
'gen-cookies',
|
|
|
|
help="Generate cookies used to access your library",
|
2020-01-19 15:40:41 +01:00
|
|
|
)
|
|
|
|
parser_gencookie.add_argument(
|
|
|
|
'-c', '--cookie-file', type=str,
|
|
|
|
help="Location of the file to store the cookie",
|
2020-01-20 00:39:28 +01:00
|
|
|
required=True,
|
2020-01-19 15:40:41 +01:00
|
|
|
)
|
2020-01-19 15:25:00 +01:00
|
|
|
|
|
|
|
###
|
|
|
|
# Download Library
|
|
|
|
###
|
2020-01-19 15:40:41 +01:00
|
|
|
# TODO: have option to only get types, ebooks, videos, etc do not enforce,
|
|
|
|
# but lower and just string match to the type in the api
|
|
|
|
parser_download = subparsers.add_parser(
|
|
|
|
'download',
|
|
|
|
help="Download content in your humble bundle library",
|
|
|
|
)
|
|
|
|
parser_download.add_argument(
|
|
|
|
'-c', '--cookie-file', type=str,
|
2020-01-20 00:39:28 +01:00
|
|
|
help="Location of the cookies file",
|
|
|
|
required=True,
|
2020-01-19 15:40:41 +01:00
|
|
|
)
|
|
|
|
parser_download.add_argument(
|
|
|
|
'-l', '--library-path', type=str,
|
|
|
|
help="Folder to download all content to",
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
parser_download.add_argument(
|
|
|
|
'--progress',
|
|
|
|
action='store_true',
|
|
|
|
help="Display progress bar for downloads",
|
|
|
|
)
|
2020-01-19 15:25:00 +01:00
|
|
|
|
|
|
|
cli_args = parser.parse_args()
|
|
|
|
|
2020-01-19 18:51:39 +01:00
|
|
|
if cli_args.action == 'gen-cookies':
|
2020-01-19 15:48:21 +01:00
|
|
|
from .generate_cookie import generate_cookie
|
2020-01-19 15:25:00 +01:00
|
|
|
generate_cookie(cli_args.cookie_file)
|
|
|
|
|
|
|
|
elif cli_args.action == 'download':
|
2020-01-19 15:48:21 +01:00
|
|
|
from .download_library import download_library
|
2020-01-19 15:40:41 +01:00
|
|
|
download_library(
|
|
|
|
cli_args.cookie_file,
|
|
|
|
cli_args.library_path,
|
|
|
|
progress_bar=cli_args.progress
|
|
|
|
)
|