From a0e7b459e185881ec566830178910a8a483f4bb0 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Thu, 25 May 2023 15:09:37 +0200 Subject: [PATCH] fix crashes and add version option --- bin/__pycache__/handler.cpython-311.pyc | Bin 10691 -> 10502 bytes imagevideoupscaler-cli.py | 116 +++++++++++++----------- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index a36c128c10be9dc12f1ed304ea8c3f0b3b8ece6a..383d385d18582bba0179a0be3067057a4ecfeec5 100644 GIT binary patch delta 356 zcmX>c+!mz1oR^o20SGpv<)uhSGcY^`abSQI%J`f&QQggwGlemQDTgbH3rurIac43_ z@h~x@GG_6@G^8*uV`N}h4a5)-#h1#rfPXThu<*p4B9?qE46z1L0zfUCS%NSnDJ-c1 zRX|P(D~N=!Q4Luj1TtW9ETe!nPpW_oP*sm1&lLSu%6Y7 zI*ekQZ!pHHGKx<&Q+J%)u5QW4o0(gXUsMvGo1apelREi>x&v1lP&3HU#a5H8Gy=E; zE-*mRl6;DXbteRdDhJeg&olq9Do1l8ge{ys3gVK#87UpoQ#NVlX3@0U4`d9EK?I zRPhB8U_I%KI*gK=r!dBJD6)KYlOXW~usG1x$ ERROR: Input and output file required! <==\n\n' ) - ap.print_usage(); - return False + if ( not args.version ): + # Check if input and output file arguments are available + if ( args.inputfile == None or args.inputfile == '' or args.outputfile == None or args.outputfile == '' ): + print( '\n\n ==> ERROR: Input and output file required! <==\n\n' ) + ap.print_usage(); + return False - # check if output file exists and if, prompt user if it should be overwritten and remove if, if yes - if ( os.path.exists( args.outputfile ) ): - doReplace = input( '--> File already exists. Do you want to replace it? (Y/n) ' ).lower() - if ( doReplace == 'y' or doReplace == '' ): - os.remove( args.outputfile ); - else: - print( '\n==> Refusing to Upscale video. Please delete the file or specify another filepath! <==' ) + # check if output file exists and if, prompt user if it should be overwritten and remove if, if yes + if ( os.path.exists( args.outputfile ) ): + doReplace = input( '--> File already exists. Do you want to replace it? (Y/n) ' ).lower() + if ( doReplace == 'y' or doReplace == '' ): + os.remove( args.outputfile ); + else: + print( '\n==> Refusing to Upscale video. Please delete the file or specify another filepath! <==' ) + return False + + # check if engine argument is valid + try: + engineInfo[ args.engine.lower() ] + except KeyError: + print( '\n==> ERROR: Engine not available. Ensure you have specified a valid engine' ) return False - # check if engine argument is valid - try: - engineInfo[ args.engine ] - except KeyError: - print( '\n==> ERROR: Engine not available. Ensure you have specified a valid engine' ) - return False - - # Check scalefactor argument and also verify that engine supports upscaling - if ( int( args.scalefactor ) > 4 and int( args.scalefactor ) < -4 ): - print( '\n==> ERROR: Invalid scale factor. Value has to be an integer between -4 and 4' ) - return False - else: - if ( not 'upscaling' in engineInfo[ args.engine ][ 'supports' ] ): - print( '\n==> ERROR: This engine does NOT support upscaling' ) + # Check scalefactor argument and also verify that engine supports upscaling + if ( args.scalefactor != None ): + if ( int( args.scalefactor ) > 4 and int( args.scalefactor ) < -4 ): + print( '\n==> ERROR: Invalid scale factor. Value has to be an integer between -4 and 4' ) + return False + else: + if ( not 'upscaling' in engineInfo[ args.engine ][ 'supports' ] ): + print( '\n==> ERROR: This engine does NOT support upscaling' ) + return False + + # Check sharpening argument and also verify that engine supports it + if ( args.sharpening != None ): + if ( float( args.sharpening ) >= 1 and float( args.sharpening ) <= 0 ): + print( '\n==> ERROR: Invalid value for sharpening. Value has to be between 0 and 1' ) + return False + else: + if ( not 'sharpening' in engineInfo[ args.engine ][ 'supports' ] ): + print( '\n==> ERROR: This engine does NOT support sharpening' ) + return False + + # check if scalefactor and / or sharpening is available + if ( ( args.scalefactor == 0 or args.scalefactor == None ) and ( args.sharpening == 0 or args.sharpening == None ) ): + print( '\n==> ERROR: Either scalefactor or sharpening argument required!' ) return False - # Check sharpening argument and also verify that engine supports it - if ( float( args.sharpening ) >= 1 and float( args.sharpening ) <= 0 ): - print( '\n==> ERROR: Invalid value for sharpening. Value has to be between 0 and 1' ) - return False - else: - if ( not 'sharpening' in engineInfo[ args.engine ][ 'supports' ] ): - print( '\n==> ERROR: This engine does NOT support sharpening' ) + # Check if filetype argument is valid + if ( not args.filetype in allowedFiletypes ): + print( '\n==> ERROR: Unknown filetype for temp files. Can be png or jpg' ) return False - - # check if scalefactor and / or sharpening is available - if ( args.scalefactor == 0 and args.sharpening == 0 ): - print( '\n==> ERROR: Either scalefactor or sharpening argument required!' ) - return False - - # Check if filetype argument is valid - if ( not args.filetype in allowedFiletypes ): - print( '\n==> ERROR: Unknown filetype for temp files. Can be png or jpg' ) - return False - - # Check if mode of engine is valid - try: - engineInfo[ args.engine ][ 'cliModeOptions' ][ args.mode ] - except KeyError: - print( '\n==> ERROR: The specified mode is not supported by this engine. Options:' ) - for option in engineInfo[ args.engine ][ 'cliModeOptions' ]: - print( ' --> ' + engineInfo[ args.engine ][ 'cliModeOptions' ][ option ][ 'displayName' ] + ' (' + option + ')' ) - return False - - return True + + # Check if mode of engine is valid + try: + engineInfo[ args.engine.lower() ][ 'cliModeOptions' ][ args.mode.lower() ] + except KeyError: + print( '\n==> ERROR: The specified mode is not supported by this engine. Options:' ) + for option in engineInfo[ args.engine ][ 'cliModeOptions' ]: + print( ' --> ' + engineInfo[ args.engine ][ 'cliModeOptions' ][ option ][ 'displayName' ] + ' (' + option + ')' ) + return False + + return True + else: + print( '\n\n==> You are running Version 1.1.0 of ImageVideoScaler-CLI <==\n' ) else: print( '\n\n==> Available engines <==\n' ) for entry in engineList: print( '--> ' + entry ) print( '\n\n' ) else: - print( '\n\n ==> INFOS about ' + engineInfo[ args.details ][ 'displayName' ] + '\n' ) + print( '\n\n ==> INFOS about ' + engineInfo[ args.details.lower() ][ 'displayName' ] + '\n' ) print( ' --> Engine cli option is: ' + engineInfo[ args.details ][ 'abbr' ].lower() ) print( ' --> CLI mode options are: ' ) for mode in engineInfo[ args.details ][ 'cliModeOptions' ]: @@ -113,6 +118,7 @@ if __name__ == '__main__': ap.add_argument( '-F', '--filetype', help='Change the file type of the temporary image files. Supports png, jpg. Video quality: png > jpg. PNG is default, if not specified.' ) ap.add_argument( '-d', '--details', help='Get details on usage of a particular engine and exit. Reads the config.json file of that engine and displays it in a HR manner' ) ap.add_argument( '-p', '--printengines', help='Print all engines and exit', action='store_true' ) + ap.add_argument( '-v', '--version', help='Print version and exit', action='store_true' ) ap.set_defaults( scaling = 0, sharpening = 0, threads = 4, engine = 'fsr', mode = 'fsr', filetype = 'png' ) args = ap.parse_args()