nodes: 0, module; 1, function_definition; 2, function_name:_set_player; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, comment:"""
          Sort the current players into priority order and set self._player
          Players are ordered by working state then prefernce supplied by user
          and finally by instance if a player has more than one running.
          """; 14, assignment; 15, pattern_list; 16, call; 17, comment:# we set the priority here as we need to establish the player name; 18, comment:# which might not be immediately available.; 19, block; 20, identifier:players; 21, block; 22, else_clause; 23, assignment; 24, assignment; 25, call; 26, identifier:players; 27, list; 28, identifier:name; 29, identifier:p; 30, attribute; 31, argument_list; 32, if_statement; 33, if_statement; 34, expression_statement; 35, block; 36, attribute; 37, call; 38, attribute; 39, identifier:top_player; 40, attribute; 41, argument_list; 42, attribute; 43, identifier:items; 44, comparison_operator:"_priority" not in p; 45, block; 46, comparison_operator:p.get("_priority") is not None; 47, block; 48, assignment; 49, expression_statement; 50, identifier:self; 51, identifier:_player; 52, attribute; 53, argument_list; 54, identifier:self; 55, identifier:_player_details; 56, attribute; 57, identifier:update; 58, identifier:self; 59, identifier:_mpris_players; 60, string:"_priority"; 61, identifier:p; 62, if_statement; 63, if_statement; 64, call; 65, None; 66, expression_statement; 67, identifier:top_player; 68, call; 69, assignment; 70, identifier:top_player; 71, identifier:get; 72, string:"_dbus_player"; 73, identifier:self; 74, identifier:py3; 75, attribute; 76, block; 77, else_clause; 78, comparison_operator:priority is not None; 79, block; 80, attribute; 81, argument_list; 82, call; 83, attribute; 84, argument_list; 85, identifier:top_player; 86, dictionary; 87, identifier:self; 88, identifier:player_priority; 89, try_statement; 90, block; 91, identifier:priority; 92, None; 93, expression_statement; 94, identifier:p; 95, identifier:get; 96, string:"_priority"; 97, attribute; 98, argument_list; 99, attribute; 100, identifier:get; 101, subscript; 102, block; 103, except_clause; 104, expression_statement; 105, assignment; 106, identifier:players; 107, identifier:append; 108, tuple; 109, identifier:self; 110, identifier:_mpris_players; 111, subscript; 112, integer:3; 113, expression_statement; 114, identifier:ValueError; 115, block; 116, assignment; 117, subscript; 118, identifier:priority; 119, subscript; 120, subscript; 121, subscript; 122, identifier:name; 123, call; 124, integer:0; 125, assignment; 126, try_statement; 127, identifier:priority; 128, integer:0; 129, identifier:p; 130, string:"_priority"; 131, identifier:p; 132, string:"_state_priority"; 133, identifier:p; 134, string:"_priority"; 135, identifier:p; 136, string:"index"; 137, identifier:sorted; 138, argument_list; 139, identifier:priority; 140, call; 141, block; 142, except_clause; 143, identifier:players; 144, attribute; 145, argument_list; 146, expression_statement; 147, identifier:ValueError; 148, block; 149, attribute; 150, identifier:index; 151, subscript; 152, assignment; 153, expression_statement; 154, identifier:self; 155, identifier:player_priority; 156, identifier:p; 157, string:"name"; 158, identifier:priority; 159, call; 160, assignment; 161, attribute; 162, argument_list; 163, identifier:priority; 164, None; 165, attribute; 166, identifier:index; 167, string:"*"; 168, identifier:self; 169, identifier:player_priority
code: def _set_player(self):
          """
          Sort the current players into priority order and set self._player
          Players are ordered by working state then prefernce supplied by user
          and finally by instance if a player has more than one running.
          """
          players = []
          for name, p in self._mpris_players.items():
              # we set the priority here as we need to establish the player name
              # which might not be immediately available.
              if "_priority" not in p:
                  if self.player_priority:
                      try:
                          priority = self.player_priority.index(p["name"])
                      except ValueError:
                          try:
                              priority = self.player_priority.index("*")
                          except ValueError:
                              priority = None
                  else:
                      priority = 0
                  if priority is not None:
                      p["_priority"] = priority
              if p.get("_priority") is not None:
                  players.append((p["_state_priority"], p["_priority"], p["index"], name))
          if players:
              top_player = self._mpris_players.get(sorted(players)[0][3])
          else:
              top_player = {}
  
          self._player = top_player.get("_dbus_player")
          self._player_details = top_player
  
          self.py3.update()