1.6 dev: Broke out check function outside of LidarrExtendedAPI. Allows -c and -t flags to share the same function. Write Wrapper function inside LidarrExtendedAPI.
This commit is contained in:
parent
79f13d273e
commit
88d4e84223
1 changed files with 44 additions and 36 deletions
|
@ -10,7 +10,6 @@ import logging
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# TODO: Breakout check function to be able to test new ARL tokens
|
|
||||||
CUSTOM_INIT_PATH = '/custom-cont_init.d/'
|
CUSTOM_INIT_PATH = '/custom-cont_init.d/'
|
||||||
CUSTOM_SERVICES_PATH = '/custom-services.d/'
|
CUSTOM_SERVICES_PATH = '/custom-services.d/'
|
||||||
STATUS_FALLBACK_LOCATION = '/custom-services.d/python/ARLStatus.txt'
|
STATUS_FALLBACK_LOCATION = '/custom-services.d/python/ARLStatus.txt'
|
||||||
|
@ -180,38 +179,22 @@ class LidarrExtendedAPI:
|
||||||
else:
|
else:
|
||||||
self.log.info('Telegram bot is disabled. Set the flag in extended.conf to enable.')
|
self.log.info('Telegram bot is disabled. Set the flag in extended.conf to enable.')
|
||||||
|
|
||||||
# Uses DeezerPlatformProvider to check if the token is valid
|
def check_token_wrapper(self): # adds Lidarr_extended specific logging and actions around check_token
|
||||||
def check_token(self, token=None):
|
self.log.info("Checking ARL Token from extended.conf")
|
||||||
self.log.info('Checking ARL Token Validity...')
|
if self.currentARLToken == '""':
|
||||||
if token == '""':
|
|
||||||
self.log.info(Fore.YELLOW+"No ARL Token set in Extended.conf"+Fore.LIGHTWHITE_EX)
|
self.log.info(Fore.YELLOW+"No ARL Token set in Extended.conf"+Fore.LIGHTWHITE_EX)
|
||||||
self.report_status("NOT SET")
|
self.report_status("NOT SET")
|
||||||
exit(0)
|
exit(0)
|
||||||
if token is None:
|
if self.currentARLToken is None:
|
||||||
self.log.error('Invalid ARL Token Entry (None Object)')
|
self.log.error('Invalid ARL Token Entry (None Object)')
|
||||||
return False
|
return False
|
||||||
try:
|
validity_results = check_token(self.currentARLToken)
|
||||||
deezer_check = DeezerPlatformProvider()
|
if validity_results is True:
|
||||||
account = deezer_check.login('', token.replace('"',''))
|
self.report_status('VALID') # For text fallback method
|
||||||
if account.plan:
|
else:
|
||||||
self.log.info(Fore.GREEN + f'Deezer Account Found.'+ Fore.LIGHTWHITE_EX)
|
|
||||||
self.log.info('-------------------------------')
|
|
||||||
self.log.info(f'Plan: {account.plan.name}')
|
|
||||||
self.log.info(f'Expiration: {account.plan.expires}')
|
|
||||||
self.log.info(f'Active: {Fore.GREEN+"Y" if account.plan.active else "N"}'+Fore.LIGHTWHITE_EX)
|
|
||||||
self.log.info(f'Download: {Fore.GREEN+"Y" if account.plan.download else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
|
||||||
self.log.info(f'Lossless: {Fore.GREEN+"Y" if account.plan.lossless else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
|
||||||
self.log.info(f'Explicit: {Fore.GREEN+"Y" if account.plan.explicit else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
|
||||||
self.log.info('-------------------------------')
|
|
||||||
self.report_status('VALID')
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
if type(e) == AuthError:
|
|
||||||
self.log.error(Fore.RED+"ARL Token Expired/Invalid. Update the token in extended.conf"+Fore.LIGHTWHITE_EX)
|
|
||||||
else:
|
|
||||||
self.log.error(e)
|
|
||||||
self.report_status('EXPIRED')
|
self.report_status('EXPIRED')
|
||||||
if self.telegram_bot_running:
|
self.log.error(Fore.RED + 'Update the token in extended.conf' + Fore.LIGHTWHITE_EX)
|
||||||
|
if self.telegram_bot_running: # Don't re-start the telegram bot if it's alread running after bot invalid token entry
|
||||||
return False
|
return False
|
||||||
if self.enable_telegram_bot:
|
if self.enable_telegram_bot:
|
||||||
self.log.info(Fore.YELLOW + 'Starting Telegram bot...Check Telegram and follow instructions.' + Fore.LIGHTWHITE_EX)
|
self.log.info(Fore.YELLOW + 'Starting Telegram bot...Check Telegram and follow instructions.' + Fore.LIGHTWHITE_EX)
|
||||||
|
@ -304,17 +287,15 @@ class TelegramBotControl:
|
||||||
await update.message.reply_text('Invalid Entry... Please try again.')
|
await update.message.reply_text('Invalid Entry... Please try again.')
|
||||||
return
|
return
|
||||||
self.log.info(Fore.YELLOW+f"Telegram Bot:Token received: {new_token}" + Fore.LIGHTWHITE_EX)
|
self.log.info(Fore.YELLOW+f"Telegram Bot:Token received: {new_token}" + Fore.LIGHTWHITE_EX)
|
||||||
token_validity = self.parent.check_token(new_token)
|
token_validity = check_token(new_token)
|
||||||
if token_validity:
|
if token_validity:
|
||||||
# await context.bot.send_message(chat_id=update.effective_chat.id, text="ARL valid, applying...")
|
|
||||||
# self.log.info(Fore.YELLOW+"TELEGRAM BOT SENT: ARL valid, applying..."+Fore.LIGHTWHITE_EX)
|
|
||||||
await send_message("ARL valid, applying...")
|
await send_message("ARL valid, applying...")
|
||||||
self.parent.newARLToken = '"'+new_token+'"'
|
self.parent.newARLToken = '"'+new_token+'"'
|
||||||
self.parent.set_new_token()
|
self.parent.set_new_token()
|
||||||
await send_message("Checking configuration")
|
await send_message("Checking configuration...")
|
||||||
# reparse extended.conf
|
# reparse extended.conf
|
||||||
self.parent.parse_extended_conf()
|
self.parent.parse_extended_conf()
|
||||||
token_validity = self.parent.check_token(self.parent.currentARLToken)
|
token_validity = check_token(self.parent.currentARLToken)
|
||||||
if token_validity:
|
if token_validity:
|
||||||
await send_message("ARL Token Updated! \U0001F44D",reply=True)
|
await send_message("ARL Token Updated! \U0001F44D",reply=True)
|
||||||
try:
|
try:
|
||||||
|
@ -327,6 +308,33 @@ class TelegramBotControl:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def check_token(token=None):
|
||||||
|
log = logging.getLogger('ARLChecker')
|
||||||
|
log.info(f"ARL Token to check: {token}")
|
||||||
|
log.info('Checking ARL Token Validity...')
|
||||||
|
try:
|
||||||
|
deezer_check = DeezerPlatformProvider()
|
||||||
|
account = deezer_check.login('', token.replace('"',''))
|
||||||
|
if account.plan:
|
||||||
|
log.info(Fore.GREEN + f'Deezer Account Found.'+ Fore.LIGHTWHITE_EX)
|
||||||
|
log.info('-------------------------------')
|
||||||
|
log.info(f'Plan: {account.plan.name}')
|
||||||
|
log.info(f'Expiration: {account.plan.expires}')
|
||||||
|
log.info(f'Active: {Fore.GREEN+"Y" if account.plan.active else "N"}'+Fore.LIGHTWHITE_EX)
|
||||||
|
log.info(f'Download: {Fore.GREEN+"Y" if account.plan.download else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
||||||
|
log.info(f'Lossless: {Fore.GREEN+"Y" if account.plan.lossless else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
||||||
|
log.info(f'Explicit: {Fore.GREEN+"Y" if account.plan.explicit else Fore.RED+"N"}'+Fore.LIGHTWHITE_EX)
|
||||||
|
log.info('-------------------------------')
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
if type(e) == AuthError:
|
||||||
|
log.error(Fore.RED + 'ARL Token Invalid/Expired.' + Fore.LIGHTWHITE_EX)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
log.error(e)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = ArgumentParser(prog='Account Checker', description='Lidarr Extended Deezer ARL Token Tools')
|
parser = ArgumentParser(prog='Account Checker', description='Lidarr Extended Deezer ARL Token Tools')
|
||||||
parser.add_argument('-c', '--check', help='Check if currently set ARL Token is active/valid',required=False, default=False, action='store_true')
|
parser.add_argument('-c', '--check', help='Check if currently set ARL Token is active/valid',required=False, default=False, action='store_true')
|
||||||
|
@ -374,7 +382,7 @@ def init_logging(version, log_file_path):
|
||||||
|
|
||||||
# Initialize colorama
|
# Initialize colorama
|
||||||
init(autoreset=True)
|
init(autoreset=True)
|
||||||
logger.info(Fore.LIGHTWHITE_EX + 'Logger initialized')
|
logger.info(Fore.GREEN + 'Logger initialized'+Fore.LIGHTWHITE_EX)
|
||||||
|
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
@ -388,17 +396,17 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.test_token:
|
if args.test_token:
|
||||||
log.info("Test flag not currently functioning. Exiting.")
|
log.info(Fore.CYAN+"CLI Token Tester"+Fore.LIGHTWHITE_EX)
|
||||||
|
check_token(args.test_token)
|
||||||
exit(0)
|
exit(0)
|
||||||
arl_checker_instance = LidarrExtendedAPI()
|
arl_checker_instance = LidarrExtendedAPI()
|
||||||
arl_checker_instance.root = root
|
arl_checker_instance.root = root
|
||||||
|
|
||||||
if args.check is True:
|
if args.check is True:
|
||||||
if arl_checker_instance.currentARLToken == '':
|
if arl_checker_instance.currentARLToken == '':
|
||||||
log.error("ARL Token not set. re-run with -n flag")
|
log.error("ARL Token not set. re-run with -n flag")
|
||||||
try:
|
try:
|
||||||
arl_checker_instance.parse_extended_conf()
|
arl_checker_instance.parse_extended_conf()
|
||||||
arl_checker_instance.check_token(arl_checker_instance.currentARLToken)
|
arl_checker_instance.check_token_wrapper()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if 'Chat not found' in str(e):
|
if 'Chat not found' in str(e):
|
||||||
log.error(Fore.RED + "Chat not found. Check your chat ID in extended.conf, or start a chat with your bot."+Fore.LIGHTWHITE_EX)
|
log.error(Fore.RED + "Chat not found. Check your chat ID in extended.conf, or start a chat with your bot."+Fore.LIGHTWHITE_EX)
|
||||||
|
|
Loading…
Reference in a new issue