示例#1
0
文件: preset.py 项目: phut/SoCo
class Service(object):
    current = 0
    stations = []
    icons = None
     
                
    def __init__(self, icons_path):
      print 'init'
      self.icons = Preset_Icon( icons_path)
      self.stations = []
      self.current = 0

    def __len__(self): 
      return len(self.stations) 

    def get_uri( self):
      station = self.stations[ int(self.current)]
      uri = station['uri']
      # TODO seems at least & needs to be escaped - should move this to play_uri and maybe escape other chars.
      uri = uri.replace('&', '&')
      return uri

    def first( self):
      self.current = 0
      
    def last( self):
       self.current = len( self.stations)-1

    def play( self, the_sonos, index=-1):
#      self.current = index
#      print self.current
      description = self.name()
      description = description + ',' + self.icon()
      ui_out.log.info( ui_out.cmd_stream_start + ',' + description)
      result = self.play_current_preset( the_sonos)
      if result == True:
        ui_out.log.info( ui_out.cmd_stream_playing + ',' + description)
      else:
        ui_out.log.error( ui_out.cmd_stream_error + ',' + description)	
      return result

    def name( self):
       desc = self.stations[self.current]['title']
       return desc
       
    def icon( self):
      if self.icons:
		return self.icons.get_icon( self.current)

    def skip( self, the_sonos, direction):
      self.current += direction
      if self.current < 0:
        raise IndexError
      return self.play( the_sonos, self.current)
示例#2
0
文件: preset.py 项目: phut/SoCo
 def __init__(self, icons_path):
   print 'init'
   self.icons = Preset_Icon( icons_path)
   self.stations = []
   self.current = 0