mirror of https://github.com/artizirk/dotfiles
Arti Zirk
5 years ago
3 changed files with 40 additions and 79 deletions
@ -1,78 +0,0 @@
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/perl |
||||
# Copyright (C) 2014 Tony Crisci <tony@dubstepdish.com> |
||||
|
||||
# This program is free software: you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation, either version 3 of the License, or |
||||
# (at your option) any later version. |
||||
|
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
|
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
||||
# Requires playerctl binary to be in your path (except cmus) |
||||
# See: https://github.com/acrisci/playerctl |
||||
|
||||
# Set instance=NAME in the i3blocks configuration to specify a music player |
||||
# (playerctl will attempt to connect to org.mpris.MediaPlayer2.[NAME] on your |
||||
# DBus session). |
||||
|
||||
use Env qw(BLOCK_INSTANCE); |
||||
|
||||
my @metadata = (); |
||||
my $player_arg = ""; |
||||
|
||||
if ($BLOCK_INSTANCE) { |
||||
$player_arg = "--player='$BLOCK_INSTANCE'"; |
||||
} |
||||
|
||||
if ($ENV{'BLOCK_BUTTON'} == 1) { |
||||
system("playerctl $player_arg previous"); |
||||
} elsif ($ENV{'BLOCK_BUTTON'} == 2) { |
||||
system("playerctl $player_arg play-pause"); |
||||
} elsif ($ENV{'BLOCK_BUTTON'} == 3) { |
||||
system("playerctl $player_arg next"); |
||||
} |
||||
|
||||
if ($player_arg eq '' or $player_arg =~ /cmus$/) { |
||||
# try cmus first |
||||
my @cmus = split /^/, qx(cmus-remote -Q); |
||||
if ($? == 0) { |
||||
foreach my $line (@cmus) { |
||||
my @data = split /\s/, $line; |
||||
if (shift @data eq 'tag') { |
||||
my $key = shift @data; |
||||
my $value = join ' ', @data; |
||||
|
||||
@metadata[0] = $value if $key eq 'artist'; |
||||
@metadata[1] = $value if $key eq 'title'; |
||||
} |
||||
} |
||||
|
||||
if (@metadata) { |
||||
# metadata found so we are done |
||||
print(join ' - ', @metadata); |
||||
exit 0; |
||||
} |
||||
} |
||||
|
||||
# if cmus was given, we are done |
||||
exit 0 unless $player_arg eq ''; |
||||
} |
||||
|
||||
my $artist = qx(playerctl $player_arg metadata artist); |
||||
chomp $artist; |
||||
# exit status will be nonzero when playerctl cannot find your player |
||||
exit(0) if $?; |
||||
push(@metadata, $artist) if $artist; |
||||
|
||||
my $title = qx(playerctl $player_arg metadata title); |
||||
chomp $title; |
||||
exit(0) if $?; |
||||
push(@metadata, $title) if $title; |
||||
|
||||
print(join(" - ", @metadata)) if @metadata; |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash |
||||
# Based on https://aur.archlinux.org/packages/playerctl/ |
||||
|
||||
INSTANCE="${BLOCK_INSTANCE}" |
||||
|
||||
if [[ "${INSTANCE}" != "" ]]; then |
||||
ARGUMENTS="--player ${INSTANCE}" |
||||
fi |
||||
|
||||
ICON_PLAY="➤" |
||||
ICON_PAUSE="Ⅱ" |
||||
ICON_STOP="[]" |
||||
CUR_ICON="" |
||||
|
||||
if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then |
||||
$(playerctl ${ARGUMENTS} previous 2>/dev/null) |
||||
elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then |
||||
$(playerctl ${ARGUMENTS} play-pause 2>/dev/null) |
||||
elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then |
||||
$(playerctl ${ARGUMENTS} next 2>/dev/null) |
||||
fi |
||||
|
||||
PLAYER_STATUS=$(playerctl ${ARGUMENTS} status 2>/dev/null) |
||||
INFO_TITLE=$(playerctl ${ARGUMENTS} metadata title 2>/dev/null) |
||||
INFO_ALBUM=$(playerctl ${ARGUMENTS} metadata album 2>/dev/null) |
||||
INFO_ARTIST=$(playerctl ${ARGUMENTS} metadata artist 2>/dev/null) |
||||
|
||||
if [[ "${PLAYER_STATUS}" = "Paused" ]]; then |
||||
CUR_ICON="${ICON_PAUSE}" |
||||
elif [[ "${PLAYER_STATUS}" = "Playing" ]]; then |
||||
CUR_ICON="${ICON_PLAY}" |
||||
else |
||||
CUR_ICON="${ICON_STOP}" |
||||
fi |
||||
|
||||
if [[ "${INFO_TITLE}" != "" ]] && [[ "${INFO_ARTIST}" != "" ]]; then |
||||
echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}" |
||||
echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}" |
||||
fi |
Loading…
Reference in new issue