diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..681a17b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +lib/ +pyvenv.cfg diff --git a/README.md b/README.md index b491173..5d4ed30 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,6 @@ Loaded with OpenEMU v1.03 usage: -ccd2cue.py convert --ccd CCDSHEET - -requared arguments: - - --ccd CCDSHEET ccd file name +ccd2cue.py --ccd [path_to_ccd] diff --git a/ccd2cue.py b/ccd2cue.py index f86c69a..4cfa6a5 100755 --- a/ccd2cue.py +++ b/ccd2cue.py @@ -1,12 +1,13 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- ''' https://github.com/crumpx/ccd2cue.git ''' -import ConfigParser +import configparser import os +from datetime import timedelta def ConfigSectionMap(Config, section): dict1 = {} @@ -26,19 +27,21 @@ def CCD2CUE(ccdsheet): cuesheet = os.path.join(filename[0]+'.cue') imagetype=('.img','.bin','.iso') imgfile = '' - files = [f for f in os.listdir('.') if os.path.isfile(f)] + basedir = os.path.dirname(ccdsheet) + files = list(filter(lambda f: os.path.isfile(os.path.join(basedir,f)), os.listdir(basedir))) for f in files: - if os.path.splitext(f)[1] in imagetype: + + if os.path.splitext(f)[1].casefold() in map(str.casefold, imagetype): imgfile = f - Config = ConfigParser.ConfigParser() + Config = configparser.ConfigParser() Config.read(ccdsheet) - cuefile = open(cuesheet, 'wb') + cuefile = open(cuesheet, 'w') track_counter = 0 BEGIN = False - cuefile.write("FILE \"%s\" BINARY\r\n" % (imgfile)) + cuefile.write("FILE \"%s\" BINARY\n" % (imgfile)) for item in Config.sections(): if 'Entry' not in item: continue @@ -49,27 +52,33 @@ def CCD2CUE(ccdsheet): trackinfo['minute'] = int(ConfigSectionMap(Config, item)['pmin']) trackinfo['second'] = int(ConfigSectionMap(Config,item)['psec']) trackinfo['frame'] = int(ConfigSectionMap(Config,item)['pframe']) + + if int(ConfigSectionMap(Config,item)['plba']) == 0: BEGIN = True - if BEGIN is True: + if BEGIN: + track_counter += 1 - if trackinfo['second'] == 0: - if trackinfo['minute'] >= 1: - trackinfo['minute'] -= 1 - trackinfo['second'] = 60 - else: - trackinfo['minute'] = 0 - trackinfo['second'] = 0 - trackinfo['second'] -= 2 - cuefile.write(" TRACK %02d %s\r\n" \ - " INDEX %02d %02d:%02d:%02d\r\n" % (track_counter, - "MODE1/2352" if tracktype == '0x04' else 'AUDIO', - trackindex, - trackinfo['minute'], - trackinfo['second'], - trackinfo['frame'],)) + + if track_counter == 1: + cuefile.write(" TRACK 01 MODE1/2352\n" \ + " INDEX 01 00:00:00\n") + else: + index0 = timedelta(minutes=trackinfo['minute'],seconds=trackinfo['second']) - timedelta(seconds=4) + index0_m = int(index0.seconds/60) + index0_s = int(index0.seconds - index0_m*60) + + index1 = timedelta(minutes=trackinfo['minute'],seconds=trackinfo['second']) - timedelta(seconds=2) + index1_m = int(index1.seconds/60) + index1_s = int(index1.seconds - index1_m*60) + + cuefile.write( + f""" TRACK {track_counter} AUDIO\n""" + f""" INDEX 00 {index0_m:02}:{index0_s:02}:{trackinfo['frame']:0>2}\n""" + f""" INDEX 01 {index1_m:02}:{index1_s:02}:{trackinfo['frame']:0>2}\n""" + ) cuefile.close() if __name__ == '__main__':