105 lines
2.3 KiB
Python
105 lines
2.3 KiB
Python
from song import Song
|
|
|
|
# Use to define various operations
|
|
class Operations:
|
|
def __init__(self,exit):
|
|
self.song = None
|
|
self.plist = None
|
|
self.library = None
|
|
self.exit = exit
|
|
self.after = 0
|
|
|
|
|
|
# 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()
|
|
|
|
|
|
def afterTrack(self,widget,data):
|
|
if (data=="qafter") and not (self.after==1):
|
|
self.after = 1
|
|
elif (data=="pafter") and not (self.after==2):
|
|
self.after = 2
|
|
else:
|
|
self.after = 0
|
|
|
|
# Advance to the next song
|
|
def next(self,widget,data):
|
|
# Close open songs
|
|
if self.song != None:
|
|
self.song.close()
|
|
# Are we exiting?
|
|
if self.after == 1:
|
|
self.exit(None,None)
|
|
# 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.setInfo = self.setInfo
|
|
# Do we begin playback?
|
|
#if self.after != 2:
|
|
self.song.play()
|
|
if self.after == 2:
|
|
self.song.pause()
|
|
self.after = 0
|
|
|
|
|
|
# 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
|
|
|
|
|
|
# Toggle random
|
|
def random(self,widget,data):
|
|
self.plist.random = not self.plist.random
|
|
|
|
|
|
def scanLib(self,dir):
|
|
self.library.scan(dir)
|