Powerline: iTunesを再生中のセグメントを追加します。

作成日 2016年05月10日  ·  5コメント  ·  ソース: powerline/powerline

OS XのiTunesから再生中のセグメントを追加できればいいのですが、Googleで現在の音楽を表示するセグメントの要点を見つけましたが、インストール方法(またはテスト方法)がわかりません。 教えてくれませんか?

segment players macos enhancement

最も参考になるコメント

気にしないでください、私は解決策を見つけて、その要点をテストしました。 float変数の変換で少し修正する必要がありました(AppleScriptはドットの代わりにコンマで「float」を返すので、「、」を「。」に置き換えてfloatに変換しました)。 これは修正されたスクリプトです。 /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')))

そしてそれは 。 私はそれが誰かを助けることを願っています😄

全てのコメント5件

気にしないでください、私は解決策を見つけて、その要点をテストしました。 float変数の変換で少し修正する必要がありました(AppleScriptはドットの代わりにコンマで「float」を返すので、「、」を「。」に置き換えてfloatに変換しました)。 これは修正されたスクリプトです。 /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')))

そしてそれは 。 私はそれが誰かを助けることを願っています😄

どういうわけか、私はまだitunesを再生してtmuxステータスラインに表示することができません。

  1. 上記のスクリプトをpowerline/segments/common/players.pyに追加します。
  2. 私のtmuxテーマファイル:
{
  "segments": {
    "right": [
      {
        "function": "powerline.segments.common.players.itunes",
        "name": "player"
      },
      ...
    ],
    ...
  }
}
  1. powerline-lintはエラーを示していません。
  2. powerline-config tmux setuplog_level=DEBUG )は、プレーヤーに関連するものを何も表示しません。

tmuxテーマに他の変更を加え、ステータスバーに反映されていることを確認しましたが、iTunesが再生されていません。
上記のスクリプトのapplescriptをテストして、目的の文字列が返されることを確認しました。これは問題ないようです。

電力線構成に何かが足りませんか?

@eliath電力線デーモンを再起動しましたか? 「ステータスバーに反映されているのを確認しました」は関係ありません。実際には、電力線は変更後に構成を再ロードすることになっており、これが機能する場合があります。 ただし、Pythonコードはリロードされません。

うん、それだけだった。 tmux設定をリロードしてデーモンを再起動すると、すべてが期待どおりに機能します。 ありがとう!

これは、少し前に#1732からマージされました。

このページは役に立ちましたか?
0 / 5 - 0 評価