From 7e0bb34e8d0c3b5c3638269f080edf2968cabe6b Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sun, 31 May 2009 23:43:01 +0000 Subject: [PATCH] Fixed finding duration git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@6 1daee41c-8060-4895-b1f0-2197c00d777a --- trunk/library.py | 5 +++-- trunk/ocarina.py | 22 +++++++++++----------- trunk/song.py | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/trunk/library.py b/trunk/library.py index 29d87510..a251ac42 100644 --- a/trunk/library.py +++ b/trunk/library.py @@ -94,6 +94,7 @@ class Library(): indices = set(self.data.map[words[0]]) for word in words[1:]: indices = indices & set(self.data.map[word]) - if len(indices) == 1: - return indices.pop() + # Return first instance + if len(indices) > 0: + return indices.pop() return -1 diff --git a/trunk/ocarina.py b/trunk/ocarina.py index bde47956..e2e70866 100644 --- a/trunk/ocarina.py +++ b/trunk/ocarina.py @@ -23,18 +23,18 @@ class main: self.song = None # If we were given a song as input, check that it exists and begin playback if len(argv) > 0: - file = os.path.expanduser(argv[0]) - if os.path.exists(file) == True: - split = file.split(self.library.data.path) - file = split[len(split)-1] - index = self.library.has(file) - info = None - if index != -1: - info = self.library.data.files[index] - else: + split = argv[0].split(self.library.data.path) + if len(split) > 0: + index = self.library.has(split[len(split)-1]) + info = None + if index != -1: + info = self.library.data.files[index] + else: + file = os.path.expanduser(argv[0]) + if os.path.exists(file): info = SongInfo() info.filename = file - #se + if info != None: self.song = Song(info,self.quit,self.commands.printLines) self.song.play() @@ -80,7 +80,7 @@ class main: if self.song == None: return cur = self.song.curTime() - tot = self.song.length + tot = self.song.info.length self.commands.printLine(cur.toStr()+" / "+tot.toStr()) # Show detailed song info diff --git a/trunk/song.py b/trunk/song.py index 5bf00011..b73a75d3 100644 --- a/trunk/song.py +++ b/trunk/song.py @@ -56,9 +56,9 @@ class Song(): def play(self): self.player.set_state(gst.STATE_PLAYING) # Start main loop and find duration (if this hasn't been done yet) - #if self.info.length == None: - # time.sleep(0.5) - # self.duration() + if self.info.length == None: + time.sleep(0.5) + self.duration() # Change state to "paused"