DBus

Oct. 9th, 2009 11:57 am
madf: (Default)
Тут, нещодавно, [livejournal.com profile] aceler писав про DBus, qdbus і всяке таке...
Я вирішив викласти свій скрипт now-playing для irssi. На Perl я ніколи нічого не писав, не сильно сваріть :)
use Irssi;
use Net::DBus;
use strict;

use vars qw($VERSION %IRSSI);

$VERSION = "2.00";
%IRSSI = (

    authors     => 'madf',
    name        => 'Amarok status',
    description => 'Shows now playing',
    license     => 'Public Domain'
);

my $bus = Net::DBus->session;

my $amarok = $bus->get_service('org.kde.amarok');
my $object = $amarok->get_object('/Player',
                                 'org.freedesktop.MediaPlayer');


sub cmd_song {
    my ($data, $server, $channel) = @_;
    my $title;

    if (!$server || !$server->{connected}) {

        Irssi::print("Not connected to server");
        return;
    }

    my $metadata = $object->GetMetadata();

    my $artist = $$metadata{"artist"};
    my $title = $$metadata{"title"};
    my $bitrate = $$metadata{"audio-bitrate"};
    
    my $out = 'np(AmK): \'' . $artist . ' - ' . $title . '\' with ' . $bitrate . ' kbps';
    
    if ($channel && ($channel->{type} eq "CHANNEL" || $channel->{type} eq "QUERY")) {

        $channel->command("MSG " . $channel->{name} . " " . $out);
    } else {

    }
    
}

Irssi::command_bind('amarok', 'cmd_song');




syntax highlighted by Code2HTML, v. 0.9.1

Profile

madf: (Default)
madf

April 2018

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 8th, 2026 11:36 pm
Powered by Dreamwidth Studios