Powerline: Ajoutez le segment iTunes en cours de lecture.

Créé le 10 mai 2016  ·  5Commentaires  ·  Source: powerline/powerline

J'aimerais pouvoir ajouter maintenant un segment de lecture à partir d'iTunes sur OS X. J'ai trouvé l' essentiel dans Google avec un segment qui montre la musique actuelle, mais je ne sais pas comment l'installer (ni même le tester). Pouvez-vous m'éclairer ?

segment players macos enhancement

Commentaire le plus utile

Qu'à cela ne tienne, j'ai trouvé une solution et j'ai testé l'essentiel. Il fallait juste une petite correction avec la conversion de la variable flottante (AppleScript renvoie "float" avec une virgule au lieu d'un point, donc j'ai juste remplacé "," en "." et converti en flottant). Ceci est un script fixe, ajoutez-le simplement à /powerline/segments/common/players.py .

class iTunesPlayerSegment(PlayerSegment):
    def get_player_status(self, pl):
        status_delimiter = '-~`/='
        ascript = '''
            tell application "System Events"
                set process_list to (name of every process)
            end tell
            if process_list contains "iTunes" then
                tell application "iTunes"
                    if player state is playing or player state is paused then
                        set t_title to name of current track
                        set t_artist to artist of current track
                        set t_album to album of current track
                        set t_duration to duration of current track
                        set t_elapsed to player position
                        set t_state to player state
                        return t_title & "{0}" & t_artist & "{0}" & t_album & "{0}" & t_elapsed & "{0}" & t_duration & "{0}" & t_state
                    end if
                end tell
            end if
        '''.format(status_delimiter)
        now_playing = asrun(pl, ascript)
        if not now_playing:
            return
        now_playing = now_playing.split(status_delimiter)
        if len(now_playing) != 6:
            return

        now_playing[4] = now_playing[4].replace(',', '.')
        title, artist = now_playing[0], now_playing[1]
        title = title[0:25] + "…" if len(title) > 25 else title
        artist = artist[0:15] + "…" if len(artist) > 15 else artist
        state = _convert_state(now_playing[5])
        total = _convert_seconds(now_playing[4])
        elapsed = _convert_seconds(float(now_playing[4]) - float(now_playing[4]))
        return {
            'title': title,
            'artist': now_playing[1],
            'album': now_playing[2],
            'total': total,
            'elapsed': elapsed,
            'state': state
        }

itunes = with_docstring(iTunesPlayerSegment(),
('''Return iTunes now playing information.
Requires ``osascript``.
{0}
''').format(_common_args.format('itunes')))

Et il semble que . J'espère que ça aidera quelqu'un

Tous les 5 commentaires

Qu'à cela ne tienne, j'ai trouvé une solution et j'ai testé l'essentiel. Il fallait juste une petite correction avec la conversion de la variable flottante (AppleScript renvoie "float" avec une virgule au lieu d'un point, donc j'ai juste remplacé "," en "." et converti en flottant). Ceci est un script fixe, ajoutez-le simplement à /powerline/segments/common/players.py .

class iTunesPlayerSegment(PlayerSegment):
    def get_player_status(self, pl):
        status_delimiter = '-~`/='
        ascript = '''
            tell application "System Events"
                set process_list to (name of every process)
            end tell
            if process_list contains "iTunes" then
                tell application "iTunes"
                    if player state is playing or player state is paused then
                        set t_title to name of current track
                        set t_artist to artist of current track
                        set t_album to album of current track
                        set t_duration to duration of current track
                        set t_elapsed to player position
                        set t_state to player state
                        return t_title & "{0}" & t_artist & "{0}" & t_album & "{0}" & t_elapsed & "{0}" & t_duration & "{0}" & t_state
                    end if
                end tell
            end if
        '''.format(status_delimiter)
        now_playing = asrun(pl, ascript)
        if not now_playing:
            return
        now_playing = now_playing.split(status_delimiter)
        if len(now_playing) != 6:
            return

        now_playing[4] = now_playing[4].replace(',', '.')
        title, artist = now_playing[0], now_playing[1]
        title = title[0:25] + "…" if len(title) > 25 else title
        artist = artist[0:15] + "…" if len(artist) > 15 else artist
        state = _convert_state(now_playing[5])
        total = _convert_seconds(now_playing[4])
        elapsed = _convert_seconds(float(now_playing[4]) - float(now_playing[4]))
        return {
            'title': title,
            'artist': now_playing[1],
            'album': now_playing[2],
            'total': total,
            'elapsed': elapsed,
            'state': state
        }

itunes = with_docstring(iTunesPlayerSegment(),
('''Return iTunes now playing information.
Requires ``osascript``.
{0}
''').format(_common_args.format('itunes')))

Et il semble que . J'espère que ça aidera quelqu'un

D'une manière ou d'une autre, je n'arrive toujours pas à faire apparaître iTunes dans ma ligne d'état tmux.

  1. J'ajoute le script ci-dessus à powerline/segments/common/players.py .
  2. Dans mon fichier de thème tmux :
{
  "segments": {
    "right": [
      {
        "function": "powerline.segments.common.players.itunes",
        "name": "player"
      },
      ...
    ],
    ...
  }
}
  1. powerline-lint n'affiche aucune erreur.
  2. powerline-config tmux setup (avec log_level=DEBUG ) n'affiche rien en rapport avec le joueur.

J'ai apporté d'autres modifications à mon thème tmux et je les vois reflétées dans ma barre d'état, mais toujours pas d'itunes en cours de lecture.
J'ai testé l'applescript du script ci-dessus pour m'assurer qu'il renvoie la chaîne souhaitée, ce qui semble être correct.

Ai-je raté quelque chose dans ma configuration CPL ?

@eliath As-tu redémarré le démon powerline ? « Je… les vois reflétés dans ma barre d'état » n'est pas pertinent : en fait, powerline est censé recharger sa configuration après des modifications et cela fonctionne parfois. Mais il ne rechargera aucun code python.

Ouais, c'était ça. Après avoir rechargé ma configuration tmux et redémarré le démon, tout fonctionne comme prévu. Merci!

Cela a été fusionné il y a quelque temps à partir de #1732.

Cette page vous a été utile?
0 / 5 - 0 notes