def main(argv): params = getParams(argv) defaultsettings = getDefaults() if 'profile' in params: profilenum = params['profile'] else: profilenum = '' profiledict = getProfile(defaultsettings, profilenum) verifyProfile(profiledict) # Let's see if we just want to show the commands in a Kodi # notification. This is useful if you want to verify settings or # cron them up manually. if 'getcommand' in params: if params['getcommand'] == 'makemkvcon': utils.showOK(buildMakeMKVConCommand(profiledict)) return 0 elif params['getcommand'] == 'handbrakecli': utils.showOK(buildHandBrakeCLICommand( profiledict, profiledict['tempfolder'])) return 0 utils.logDebug(profiledict) command = buildMakeMKVConCommand(profiledict) # TODO (??) user might want to specify a disc name in case the disc name # is shortened or changed in a way that metadata libraries don't understand # what movie this is. many times though, the below will give you what you want discName = getDiscName(profiledict) # Beginning Rip. Command: utils.log('{beginning} {rip}. {commandstr}: {command}'.format( beginning = utils.getString(30070), rip = utils.getString(30027), commandstr = utils.getString(30071), command = command)) try: if sys.version_info[:2] == (2,7): ripoutput = subprocess.check_output( command, stderr=subprocess.STDOUT, shell=True) elif sys.version_info[:2] == (2,6): ripoutput = utils.check_output( command, stderr=subprocess.STDOUT, shell=True) # For some reason, it seems that this always exits with a non-zero # status, so I'm just checking the output for success. except subprocess.CalledProcessError, e: if 'Copy complete.' in e.output: # We'll check for an error which denote using FAT32 for the temp # filesystem. fatcheck = re.search( r"The size of output file '(.*)' may reach " "as much as (.*) while target filesystem has a file size " "limit of (.*)", output) if fatcheck: # 30083 = Temp folder cannot handle large files # 30084 = This is usually caused by using FAT32 for storage. utils.exitFailed(utils.getstring(30083), utils.getString(30083) + ' ' + utils.getString(30084)) if ('The source file' in e.output and ' is corrupt or invalid at offset' in e.output and ', attempting to work around' in e.output): # 30087 = MakeMKV Had Trouble Reading the Disc. Try Cleaning it # if the Correct Title Wasn't Ripped. utils.log(utils.getString(30087)) else: if 'Your temporary key has expired and was removed' in e.output: # 30074 = Your temporary MakeMKV key has expired. Please update # it utils.exitFailed(utils.getString(30074), utils.getString(30074)) if 'This application version is too old' in e.output: # 30075 = Your version of MakeMKV is too old. Please update it. utils.exitFailed(utils.getString(30075), utils.getString(30075)) if 'Failed to open disc' in e.output: # 30085 = Failed to Open Disc utils.exitFailed(utils.getString(30085), utils.getString(30085)) if ('The source file' in e.output and ' is corrupt or invalid at offset' in e.output and ', attempting to work around' in e.output): # 30086 = MakeMKV Had Trouble Reading the Disc. Try Cleaning it utils.exitFailed(utils.getString(30086), utils.getString(30086)) utils.exitFailed('MakeMKV {failed}'.format( failed = utils.getString(30059)), e.output)
def main(argv): params = getParams(argv) defaultsettings = getDefaults() if 'profile' in params: profilenum = params['profile'] else: profilenum = '' profiledict = getProfile(defaultsettings, profilenum) verifyProfile(profiledict) # Let's see if we just want to show the commands in a Kodi # notification. This is useful if you want to verify settings or # cron them up manually. if 'getcommand' in params: if params['getcommand'] == 'makemkvcon': utils.showOK(buildMakeMKVConCommand(profiledict)) return 0 elif params['getcommand'] == 'handbrakecli': utils.showOK(buildHandBrakeCLICommand( profiledict, profiledict['tempfolder'])) return 0 utils.logDebug(profiledict) command = buildMakeMKVConCommand(profiledict) # Beginning Rip. Command: utils.log('{beginning} {rip}. {commandstr}: {command}'.format( beginning = utils.getString(30070), rip = utils.getString(30027), commandstr = utils.getString(30071), command = command)) try: if sys.version_info[:2] == (2,7): ripoutput = subprocess.check_output( command, stderr=subprocess.STDOUT, shell=True) elif sys.version_info[:2] == (2,6): ripoutput = utils.check_output( command, stderr=subprocess.STDOUT, shell=True) # For some reason, it seems that this always exits with a non-zero # status, so I'm just checking the output for success. except subprocess.CalledProcessError, e: if 'Copy complete.' in e.output: # We'll check for an error which denote using FAT32 for the temp # filesystem. fatcheck = re.search( r"The size of output file '(.*)' may reach " "as much as (.*) while target filesystem has a file size " "limit of (.*)", output) if fatcheck: # 30083 = Temp folder cannot handle large files # 30084 = This is usually caused by using FAT32 for storage. utils.exitFailed(utils.getstring(30083), utils.getString(30083) + ' ' + utils.getString(30084)) if ('The source file' in e.output and ' is corrupt or invalid at offset' in e.output and ', attempting to work around' in e.output): # 30087 = MakeMKV Had Trouble Reading the Disc. Try Cleaning it # if the Correct Title Wasn't Ripped. utils.log(utils.getString(30087)) else: if 'Your temporary key has expired and was removed' in e.output: # 30074 = Your temporary MakeMKV key has expired. Please update # it utils.exitFailed(utils.getString(30074), utils.getString(30074)) if 'This application version is too old' in e.output: # 30075 = Your version of MakeMKV is too old. Please update it. utils.exitFailed(utils.getString(30075), utils.getString(30075)) if 'Failed to open disc' in e.output: # 30085 = Failed to Open Disc utils.exitFailed(utils.getString(30085), utils.getString(30085)) if ('The source file' in e.output and ' is corrupt or invalid at offset' in e.output and ', attempting to work around' in e.output): # 30086 = MakeMKV Had Trouble Reading the Disc. Try Cleaning it utils.exitFailed(utils.getString(30086), utils.getString(30086)) utils.exitFailed('MakeMKV {failed}'.format( failed = utils.getString(30059)), e.output)
# 30027 == Rip if profiledict['ejectafter'] == utils.getStringLow(30027): xbmc.executebuiltin('EjectTray()') # Display notification/dialog if we need to. A notification is a # toast that auto-dismisses after a few seconds, whereas a dialog # requires the user to press ok. # 30065 == Notification if profiledict['notifyafterrip'] == utils.getStringLow(30065): utils.showNotification('{rip} {completedsuccessfully}'.format( rip = utils.getString(30027), completedsuccessfully = utils.getString(30058))) # 30066 == Dialog elif profiledict['notifyafterrip'] == utils.getStringLow(30066): utils.showOK('{rip} {completedsuccessfully}'.format( rip = utils.getString(30027), completedsuccessfully = utils.getString(30058))) # Some people may want to just rip movies, and not encode them. # If that's the case, we are done here. if profiledict['encodeafterrip'] == 'false': return 0 filestoencode = glob.glob(os.path.join(profiledict['tempfolder'], '*.mkv')) for f in filestoencode: # makemkvcon doesn't allow to customize the output filename # but handbrake does, so pass it in to customize output filename option command = buildHandBrakeCLICommand(profiledict, f, discName) utils.log('{beginning} {encode}. {commandstr}: {command}'.format( beginning = utils.getString(30070), encode = utils.getString(30028),
# 30027 == Rip if profiledict['ejectafter'] == utils.getStringLow(30027): xbmc.executebuiltin('EjectTray()') # Display notification/dialog if we need to. A notification is a # toast that auto-dismisses after a few seconds, whereas a dialog # requires the user to press ok. # 30065 == Notification if profiledict['notifyafterrip'] == utils.getStringLow(30065): utils.showNotification('{rip} {completedsuccessfully}'.format( rip = utils.getString(30027), completedsuccessfully = utils.getString(30058))) # 30066 == Dialog elif profiledict['notifyafterrip'] == utils.getStringLow(30066): utils.showOK('{rip} {completedsuccessfully}'.format( rip = utils.getString(30027), completedsuccessfully = utils.getString(30058))) # Some people may want to just rip movies, and not encode them. # If that's the case, we are done here. if profiledict['encodeafterrip'] == 'false': return 0 filestoencode = glob.glob(os.path.join(profiledict['tempfolder'], '*.mkv')) for f in filestoencode: command = buildHandBrakeCLICommand(profiledict, f) utils.log('{beginning} {encode}. {commandstr}: {command}'.format( beginning = utils.getString(30070), encode = utils.getString(30028), commandstr = utils.getString(30071), command = command))