Skip to content

Instantly share code, notes, and snippets.

@longjoel
Last active February 12, 2019 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save longjoel/fe68eb5066306b18e3023409adc40d16 to your computer and use it in GitHub Desktop.
Save longjoel/fe68eb5066306b18e3023409adc40d16 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import subprocess
import os
import sys
#
#variables
#
psxRipDir = "/media/longjoel/New Volume/PS1/"
requiredPrograms = ["cdrdao", "eject", "toc2cue"]
volumeBlacklist = ["boot", "retropie"]
cmdGetDrivesByLabel = "/dev/disk/by-label/"
readCdRomParams =["cdrdao","read-cd",
"--read-raw",
"--read-subchan", "rw_raw",
"--datafile",psxRipDir+"[GAME_NAME].bin",
"--device", "/dev/cdrom",
"--driver", "generic-mmc-raw",
psxRipDir+"[GAME_NAME].toc"]
toCue =["toc2cue",
psxRipDir+"[GAME_NAME].toc",
psxRipDir+"[GAME_NAME].cue"]
#
#Check and see if a given dependency is satisfied.
#
def isTool(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return True
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return True
return False
#
#Check if dependencies have been satisfied.
#
def hasDependencies(dependencies):
for d in dependencies:
if not isTool(d):
return False
return True
#
#Check and see if there is a CD inserted. Get the name of the volume.
#assuming that
#
def getDiscName():
if len(sys.argv) > 1:
return sys.argv[1]
labels = os.listdir(cmdGetDrivesByLabel)
for label in labels:
if not label in volumeBlacklist:
return label
return ""
#
#Rip the game.
#
def ripGame(gameName):
try:
print ("Ripping "+gameName+".")
replacedArgs = []
for arg in readCdRomParams:
replacedArgs.append(arg.replace("[GAME_NAME]", gameName))
subprocess.call(replacedArgs)
except:
return False
return True
def tocToCue(gameName):
replacedArgs=[]
for arg in toCue:
replacedArgs.append(arg.replace("[GAME_NAME]", gameName))
subprocess.call(replacedArgs)
def cleanToc(gameName):
tocFileName = (psxRipDir+"[GAME_NAME].toc").replace("[GAME_NAME]",gameName)
if(os.path.isfile(tocFileName)):
os.remove(tocFileName)
#
#Main entrypoint
#
def main():
if not hasDependencies(requiredPrograms):
print("Dependencies have not been satisfied. Please run 'sudo apt-get install cdrdao'.")
return
discName = getDiscName()
if discName == "":
print("No Disc has been detected. ")
return
cleanToc(discName)
if ripGame(discName):
print("writing cue file")
tocToCue(discName)
subprocess.call("eject")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment