From bce17ff3a2457b60387a1df8cc93c4991ff03938 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 13 Apr 2009 20:35:36 +0000 Subject: [PATCH] * morituri/image/image.py: Also look for audio file basename relative to cue file. --- ChangeLog | 5 +++++ morituri/image/image.py | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37db8ea..89d08d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-13 Thomas Vander Stichele + + * morituri/image/image.py: + Also look for audio file basename relative to cue file. + 2009-04-13 Thomas Vander Stichele * examples/ARcue.py: diff --git a/morituri/image/image.py b/morituri/image/image.py index bdd36e8..fb3f3cd 100644 --- a/morituri/image/image.py +++ b/morituri/image/image.py @@ -52,15 +52,25 @@ class Image: # .cue FILE statements have Windows-style path separators, so convert tpath = os.path.join(*path.split('\\')) - # if the path is relative, make it absolute relative to the cue file - if tpath != os.path.abspath(tpath): - tpath = os.path.join(os.path.dirname(self._path), tpath) + candidatePaths = [] - noext, _ = os.path.splitext(tpath) - for ext in ['wav', 'flac']: - cpath = '%s.%s' % (noext, ext) - if os.path.exists(cpath): - return cpath + # if the path is relative: + # - check relatively to the cue file + # - check only the filename part relative to the cue file + if tpath == os.path.abspath(tpath): + candidatePaths.append(tPath) + else: + candidatePaths.append(os.path.join( + os.path.dirname(self._path), tpath)) + candidatePaths.append(os.path.join( + os.path.dirname(self._path), os.path.basename(tpath))) + + for candidate in candidatePaths: + noext, _ = os.path.splitext(candidate) + for ext in ['wav', 'flac']: + cpath = '%s.%s' % (noext, ext) + if os.path.exists(cpath): + return cpath raise KeyError, "Cannot find file for %s" % path