def main(): # Arguments arguments = getArguments() # Make sure a file path was passed from radarr if arguments['file'] is not None: # Make sure file path exists if not os.path.isfile(arguments['file']): print('\033[91mERROR:\033[0m The provided file path does not exist. Check your arguments.') sys.exit() # Get variables for the download script try: directory = os.path.abspath(os.path.dirname(arguments['file'])) title = os.path.basename(directory)[0:os.path.basename(directory).rfind('(')].strip() year = os.path.basename(directory)[os.path.basename(directory).rindex('(')+1:].split(')')[0].strip() except: print(arguments['file']) print('\033[93mWARNING:\033[0m Failed to extract title and year from file. Skipping...') sys.exit() # Set up arguments for other script sys.argv = [os.path.split(os.path.abspath(__file__))[0]+'/download.py', '--title', title, '--year', year, '--directory', directory] # Run other script downloadItem() else: print('\033[91mERROR:\033[0m you must pass a file to the script. Are you sure Tautulli fired this?')
def main(): # Arguments arguments = getArguments() # Settings settings = getSettings() # Make sure a directory was passed if arguments['directory'] is not None: # Make sure directory exists if not os.path.exists(arguments['directory']): print('\033[91mERROR:\033[0m The specified directory does not exist. Check your arguments.') sys.exit() # Iterate through items in directory for item in os.listdir(arguments['directory']): # Make sure the item is a directory if os.path.isdir(arguments['directory']+'/'+item): # Get variables for the download script title = None year = None directory = None try: title = item[0:item.rfind('(')].strip() year = item[item.rindex('(')+1:].split(')')[0].strip() directory = arguments['directory']+'/'+item except: print(item) print('\033[93mWARNING:\033[0m Failed to extract title and year from folder name. Skipping.') if title is not None and year is not None and directory is not None: # If subfolder setting is set, add it to the destination directory if settings['subfolder'].strip(): destination = directory+'/'+settings['subfolder'] else: destination = directory # Use custom formatting for filenames or use default if none is set if settings['custom_formatting'].strip(): filename = settings['custom_formatting'].replace('%title%', title).replace('%year%', year)+'.mp4' else: filename = title+' ('+year+')-trailer.mp4' # Make sure the trailer has not already been downloaded if not os.path.exists(destination+'/'+filename): # Print current item print(item) # Set up arguments for other script sys.argv = [os.path.split(os.path.abspath(__file__))[0]+'/download.py', '--title', title, '--year', year, '--directory', directory] # Run other script downloadItem() else: print('\033[91mERROR:\033[0m you must pass a directory to the script')
def main(): # Arguments arguments = getArguments() # Make sure a file path was passed from radarr if arguments['file'] is not None: # In case some Radarr versions end this variable with a slash, remove it arguments['file'] = arguments['file'].rstrip("\\/") if '/' in arguments['file']: arguments['file'] += '/' else: arguments['file'] += "\\" # Make sure file path exists if not os.path.isdir(arguments['file']): print( '\033[91mERROR:\033[0m The provided file path does not exist. Check your arguments.' ) sys.exit() # Get variables for the download script try: directory = os.path.abspath(os.path.dirname(arguments['file'])) title = os.path.basename( directory)[0:os.path.basename(directory).rfind('(')].strip() year = os.path.basename( directory)[os.path.basename(directory).rindex('(') + 1:].split(')')[0].strip() except: print(arguments['file']) print( '\033[93mWARNING:\033[0m Failed to extract title and year from radarr movie path. Skipping...' ) sys.exit() # Set up arguments for other script sys.argv = [ os.path.split(os.path.abspath(__file__))[0] + '/download.py', '--title', title, '--year', year, '--directory', directory ] # Run other script downloadItem() else: print( '\033[91mERROR:\033[0m you must pass the radarr movie path environment variable to the script. Are you sure Radarr fired this?' )