コード例 #1
0
ファイル: managempris.py プロジェクト: pat1/autoradio
def player_watchdog(player,session):

   logging.debug( "player_watchdog: test if player is running" )

   try:

      if  player == "vlc" or player == "AutoPlayer":
         aud = autompris2.mediaplayer(player=player,session=session)
      else:
         aud = autompris.mediaplayer(player=player,session=session)

   except:
      logging.error("player_watchdog: player do not communicate on d-bus")

      if player == "audacious" or player == "xmms":
         import subprocess
         try:
            logging.info("player_watchdog: try launching player")
            subprocess.Popen(player , shell=True)
         except:
            logging.error("player_watchdog: error launching "+player)
            if player == "xmms":
               try:
                  logging.info("player_watchdog: try launching "+player+"2")
                  subprocess.Popen(player+"2" , shell=True)
               except:
                  logging.error("player_watchdog: error launching "+player+"2")

      import time
      time.sleep(5)
      logging.info("player_watchdog: player executed")

      try:
         if  player == "vlc" or player == "AutoPlayer":
            aud = autompris2.mediaplayer(player=player,session=session)
         else:
            aud = autompris.mediaplayer(player=player,session=session)

      except:
         logging.error("player_watchdog serious problem: player do not comunicate on d-bus")

   try:
      aud.play_ifnot()
      logging.debug("player_watchdog: start playing if not")

   except:
      logging.error("player_watchdog: cannot start playing if not")

   return True
コード例 #2
0
ファイル: managempris.py プロジェクト: pat1/autoradio
def ManagePlayer (player,session,schedule):
   "Manage player to do operation on media"
    
   try:

      if ( schedule.type == "spot" ): 
         operation="queueMedia"
      elif ( schedule.type == "program" ): 
         operation="queueMedia"
      elif ( schedule.type == "jingle" ):
         operation="queueMedia"
      elif ( schedule.type == "playlist" ):
         operation="loadPlaylist"
      else:
         raise PlayerError("Managempris: type not supported: %s"% schedule.type)

      try:
         if operation == "loadPlaylist":
            media=shuffle_playlist(schedule.filename,schedule.shuffle,relative_path=False,length=schedule.maxlength)
         else:
            media=schedule.filename

         if  player == "vlc" or player == "AutoPlayer":
            aud = autompris2.mediaplayer(player=player,session=session)
         else:
            aud = autompris.mediaplayer(player=player,session=session)
      except:
         raise PlayerError("Managempris: error connecting to player dbus")
         
      # Regione critica
      lock.acquire()
      try:
         if not aud.playlist_clear_up(atlast=10):
            raise PlayerError("Managempris: ERROR in playlist_clear_up")

         #print settings.MEDIA_ROOT
         pos=aud.get_playlist_posauto(autopath=settings.MEDIA_ROOT,securesec=10)
         curpos=aud.get_playlist_pos()

         # inserisco il file nella playlist
         if pos is None:
            raise PlayerError("Managempris: ERROR in xmms.control.get_playlist_posauto")

         logging.info( "ManageXmms: insert media: %s at position %d",media,pos)
         aud.playlist_add_atpos("file://"+media,pos)
                
         # recheck for consistency
         newpos=aud.get_playlist_pos()
         if curpos != newpos:
            raise PlayerError("Managempris: strange ERROR: consinstency problem; pos: %s , newpos: %s"% (str(curpos),str(newpos)))

         if not aud.playlist_clear_down(atlast=500):
            raise PlayerError("Managempris: ERROR in playlist_clear_down")

      finally:
         #signal.alarm(0)
         lock.release()

         # here we have a problem ... sometime the player is not ready when the file is deleted !
         # so we comment it out
#         if schedule.shuffle:
#            os.remove(media)

      logging.info( "Managempris: write   in django: %s",schedule.djobj)
      ar_emitted(schedule.djobj)
      logging.info( "Managempris: written in django: %s",schedule.djobj)

      aud.play_ifnot()

   except PlayerError, e:
      logging.error(e)
コード例 #3
0
ファイル: mprisweb.py プロジェクト: pat1/autoradio
    def index(self):
        "return media player playlist"


        if (self.iht) :
            htmlresponse=head
        else:
            htmlresponse=""

        try:
            if  self.player == "vlc" or self.player == "AutoPlayer":
                mp= autompris2.mediaplayer(player=self.player,session=0)
            else:
                mp= autompris.mediaplayer(player=self.player,session=0)

        except:
            return "error intializing dbus"

        try:
            cpos=mp.get_playlist_pos()
	    if cpos is None: cpos=0
	    cpos=int(cpos)

        except:
            return "error get_playlist_pos()"
	
        try:
            isplaying= mp.isplaying()

        except:
            return "error isplaying()"

        try:
            len=mp.get_playlist_len()
            htmlresponse+='<p>player have %i songs in playlist // song number %i selected</p>' % (len,cpos+1)
            htmlresponse+='<table border="1">'
            htmlresponse+='<td>position</td><td>lenght // remain</td><td>media</td>'

            for pos in xrange(0,min(len,maxplele)):
                htmlresponse+='<tr>'
                metadata=mp.get_metadata(pos)

                timelength=datetime.timedelta(seconds=datetime.timedelta(milliseconds=metadata["mtimelength"]).seconds)
                timeposition=datetime.timedelta(seconds=datetime.timedelta(milliseconds=metadata["mtimeposition"]).seconds)

                if pos == cpos and isplaying:
                    col="#FF0000"
                    toend=timelength-timeposition
                elif  pos < cpos :
                    col="#0000FF"
                    toend=""
                else:
                    col="#00FF00"
                    toend=""

                if (metadata["artist"] is not None) or (metadata["title"] is not None):
                    htmlresponse+='<td bgcolor="%s">%i</td><td> %s // %s </td><td><a href="%s">%s // %s</a></td>' % \
                    (col,pos+1,str(timelength),str(toend),metadata["file"],metadata["artist"],metadata["title"])
                else:
                    purefilename=os.path.splitext(metadata["file"])[0]
                    htmlresponse+='<td bgcolor="%s">%i</td><td> %s // %s </td><td><a href="%s">%s</a></td>' % \
                    (col,pos+1,str(timelength),str(toend),metadata["file"],os.path.basename(purefilename))


                htmlresponse+='</tr>'

        except:
		htmlresponse+='error getting player information'

        htmlresponse+='</table>'

	try:
		if len > maxplele :
			htmlresponse+="<p>ATTENTION: there are more file than you can see here.</p>"
	except:
		pass

        if (self.iht) :
            htmlresponse+=tail
        return htmlresponse