-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathdeadbeef.pl
105 lines (91 loc) · 2.22 KB
/
deadbeef.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#
# 2021-02-25
# - fix typos in the help comments
#
# 2017-12-30 bcattaneo:
# - initial release
#
use Irssi;
use Irssi::Irc;
use strict;
use vars qw($VERSION %IRSSI);
#
# List of commands:
# /np - now playing
# /dbplay - Start playback
# /dbstop - Stop playback
# /dbpause - Pause playback
# /dbnext - Next song in playlist
# /dbprev - Previous song in playlist
# /dbrandom - Random song in playlist
#
# Settings:
# /set deadbeef_format [Formatting syntax for "now playing" command]
# For more info, see https://github.com/DeaDBeeF-Player/deadbeef/wiki/Title-formatting
#
our $VERSION = '1.0.1';
our %IRSSI = (
authors => 'bcattaneo',
name => 'deadbeef',
url => 'http://github.com/bcattaneo',
description => 'deadbeef control and now playing script',
license => 'Public Domain',
#changed => "2021-02-25",
);
Irssi::settings_add_str('deadbeef', 'deadbeef_format' => '%a - %t');
my $deadbeef = "deadbeef.pl";
#########################
## Now playing command ##
#########################
sub now_playing {
my ($data, $server, $witem) = @_;
my $format = Irssi::settings_get_str('deadbeef_format');
my $output = (split("\n",`deadbeef --nowplaying "$format" 2>&1`))[-1];
if ($output ne "nothing" )
{
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY"))
{
$witem->command("me nowplaying: $output")
}
else
{
Irssi::print("%_$deadbeef%_ - Not a channel/query!");
}
}
else
{
Irssi::print("%_$deadbeef%_ - Play something!");
}
}
##############
## Controls ##
##############
sub play {
system("deadbeef --play &> /dev/null");
}
sub stop {
system("deadbeef --stop &> /dev/null");
}
sub pause {
system("deadbeef --pause &> /dev/null");
}
sub next {
system("deadbeef --next &> /dev/null");
}
sub prev {
system("deadbeef --prev &> /dev/null");
}
sub random {
system("deadbeef --prev &> /dev/null");
}
#####################
## Command binding ##
#####################
Irssi::command_bind('np', 'now_playing');
Irssi::command_bind('dbplay', 'play');
Irssi::command_bind('dbstop', 'stop');
Irssi::command_bind('dbpause', 'pause');
Irssi::command_bind('dbnext', 'next');
Irssi::command_bind('dbprev', 'prev');
Irssi::command_bind('dbrandom', 'random');