Added config support.

This commit is contained in:
CronyAkatsuki 2021-12-14 21:13:17 +01:00
parent 0e12897992
commit 31895e62d3

25
adl.py
View File

@ -7,7 +7,7 @@ PROBLEMATIC_TITLES = open(DN + "/problem_title.txt").readlines() # list of probl
FZF_FILE = open(DN + "/fzf.txt", "w+") # temp file for fzf FZF_FILE = open(DN + "/fzf.txt", "w+") # temp file for fzf
FZF_FILE_PATH = DN +"/fzf.txt" # path of the temp file FZF_FILE_PATH = DN +"/fzf.txt" # path of the temp file
PRINT_FZF_PATH = "python " + DN + "/print_fzf.py" # print the fzf file PRINT_FZF_PATH = "python " + DN + "/print_fzf.py" # print the fzf file
CONFIG_FILE_PATH = os.path.join('C\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json') CONFIG_FILE_PATH = os.path.join('C:\\', 'Users', str(os.getlogin()), 'Documents', 'Adl', 'config.json')
# exit function # exit function
def exit_adl(): def exit_adl():
@ -240,7 +240,15 @@ def choose_episode_specific_show():
color_print(" S - Skip. Exit adl.") color_print(" S - Skip. Exit adl.")
return color_prommpt("Your choice? [A/i/c/s]: ") return color_prommpt("Your choice? [A/i/c/s]: ")
def argument_parser(): def argument_and_config_parser():
# config
config = {}
ConfigExists = False
if os.path.exists(CONFIG_FILE_PATH):
config_content = open(CONFIG_FILE_PATH, encoding='utf-8-sig').read()
config = eval(config_content)
ConfigExists = True
# argument parser # argument parser
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
@ -264,8 +272,6 @@ def argument_parser():
help="Display version and exit") help="Display version and exit")
args = vars(ap.parse_args()) args = vars(ap.parse_args())
print(args)
# print the version # print the version
if args["version"]: if args["version"]:
@ -285,12 +291,16 @@ def argument_parser():
# get player # get player
if args["player"]: if args["player"]:
player = str(args["player"]) # get player from user player = str(args["player"]) # get player from user
elif ConfigExists and 'player' in config and config["player"]:
player = str(config["player"]) # get player from config
else: else:
player = "mpv" # default player player = "mpv" # default player
# get provider # get provider
if args['provider']: if args['provider']:
provider = str(args["provider"]) provider = str(args["provider"])
elif ConfigExists and 'provider' in config and config['provider']:
provider = str(config["provider"])
else: else:
provider = "" provider = ""
@ -313,6 +323,8 @@ def argument_parser():
# get account # get account
if args['account']: if args['account']:
account = str(int(args["account"]) - 1) # take the account from input account = str(int(args["account"]) - 1) # take the account from input
elif ConfigExists and 'account' in config and config["account"]:
account = str(int(config["account"]) - 1) # take the account from config
else: else:
account = "0" # default account account = "0" # default account
@ -324,7 +336,6 @@ def argument_parser():
download = False # specify whether to download or not download = False # specify whether to download or not
msg = "watching" # msg for the watch prompt msg = "watching" # msg for the watch prompt
return (player, provider, show, episode, account, download, msg) return (player, provider, show, episode, account, download, msg)
def specific_show_loop(show, msg, download, provider, player): def specific_show_loop(show, msg, download, provider, player):
@ -457,8 +468,8 @@ def main():
os.environ['LINES'] = '25' os.environ['LINES'] = '25'
os.environ['COLUMNS'] = '120' os.environ['COLUMNS'] = '120'
# get argument parametes # get argument and config parameters
(player, provider, show, episode, account, download, msg) = argument_parser() (player, provider, show, episode, account, download, msg) = argument_and_config_parser()
# retrieve the trackma list on run # retrieve the trackma list on run
retrieve = True retrieve = True