dotfiles/.config/weechat/perl/kodinp.pl.org
2025-05-28 18:33:04 +02:00

1.6 KiB
Executable File

#!/usr/bin/perl use LWP::Simple;

my $script_name = "kodinp"; my $author = "multiple"; my $version = "0.1"; my $license = "Public domain"; my $description = "Get current song from kodi";

weechat::register($script_name, $author, $version, $license, $description, "", ""); weechat::hook_command("kodi", "Get current song from kodi", "", "", "", "kodi", "");

my $ip = "192.168.1.130"; my $port = "8080";

my $artist; my $title; my $album; my $np;

sub kodi {

my $content = get("http://$ip:$port/jsonrpc?request={%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20{%20%22properties%22:%20[%22artist%22,%20%22title%22,%20%22album%22],%20%22playerid%22:%200%20},%22id%22:%20%22AudioGetItem%22}"); die "get failed" if (!defined $content);

if($content =~ m/"artist":\[(.*?)\]/i) { $artist = $1; $artist =~ s/"//g; } if($content =~ m/"title":"(.*?)"/i) { $title = $1; } if($content =~ m/"album":"(.*?)"/i) { $album = $1; }

if (!defined $artist){ $np = $title; } else { $np = $artist . " - " . $title . " (" . $album . ")"; }

undef $title; undef $artist; undef $album;

if (defined $np){ weechat::command("", "/me np: $np"); } return 1; }