ocarina/trunk/operations.py

77 lines
1.7 KiB
Python

from song import Song
# Use to define various operations
class Operations:
def __init__(self):
self.song = None
self.plist = None
self.library = None
# Begin playback
def play(self,widget,data):
if self.song == None:
return
self.song.play()
# Pause playback
def pause(self,widget,data):
if self.song == None:
return
self.song.pause()
# Advance to the next song
def next(self,widget,data):
# Close open songs
if self.song != None:
self.song.close()
# Get next song
index = self.plist.next()
if index > -1:
self.song = None
info = self.library.data.files[index]
self.song = Song(info,self.next)
if index > -2:
self.song.play()
# Mark progress on the progress bar
def markProgress(self,widget,data):
time = (False,None)
while time[0] == False:
time = self.song.curTime()
widget.set_fraction(float(self.song.current)/float(self.song.total))
widget.set_text(time[1].toStr()+" / "+self.song.info.length.toStr())
#print float(self.song.current)/float(self.song.total)
return True
def this(self,widget,data):
# Return if no song found
if self.song == None:
return
# Return if no tags found
if self.song.info.tags == None:
print "Could not find any tags"
return
fields = ["title","artist","track-number","track-count","album"]
for field in fields:
if (field in self.song.info.tags.keys()) == True:
print field+":",self.song.info.tags[field]
# Print detailed song info
def info(self,widget,data):
# Return if no song found
if self.song == None:
return
# Return if no tags found
if self.song.info.tags == None:
print "Could not find any tags"
return
for tag in self.song.info.tags.keys():
print tag+":",self.song.info.tags[tag]
print self.song.info.filename