All pastes #825049 Raw Edit

Exaile-irssi script

public text v1 · immutable
#825049 ·published 2007-12-20 09:20 UTC
rendered paste body
#!/usr/bin/perl
# Made by Adam Olsen, arolsen \@ gmail (dot) com
# Modified by Krunoslav Husak, h00s \@ h00s (dot) org

use Net::DBus;
#use strict;
use Irssi;
use vars qw($VERSION %IRSSI);

$VERSION = "1.0";
%IRSSI = (
	authors => "Adam Olsen",
	contact => "arolsen\@gmail.com",
	name => "Exaile interface script",
	description => "Prints what you're playing to an irssi channel",
	license => "Public domain"
);

sub test_dbus
{
	my $service = shift;

	my $bus = Net::DBus->session;
	my $obj = $bus->get_service("org.freedesktop.DBus");
	my $iface = $obj->get_object("/org/freedesktop/DBus", 
		"org.freedesktop.DBus");

	foreach my $item( @{$iface->ListNames()} )
	{
		if( $item eq $service )
		{
			return 1;
		}
	}

	return 0;
}

sub print_info
{
	my($data, $server, $witem) = @_;

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

	if(!&test_dbus("org.exaile.DBusInterface"))
	{
		print "Could not see Exaile in dbus.";
		return;
	}

	my $obj = $bus->get_service("org.exaile.DBusInterface");
	my $iface = $obj->get_object("/DBusInterfaceObject",
		"org.exaile.DBusInterface");

	my $pos = $iface->current_position;
	if(!$pos)
	{	
		$pos = -1;
	}
	$pos = int($pos);

#fetch information
	my $song = $iface->get_title;
	my $artist = $iface->get_artist;
	my $album = $iface->get_album;
	my $length = $iface->get_length;
	my $year = $iface->get_track_attr(year);
	my $file = $iface->get_track_attr(filename);
	my $track = $iface->get_track_attr(track);

#initial h4x0ry
	my $artist1 = "";
	my $albtxt = "";
	my $tracktmp = "";
	my $yeartmp = "";
	my $songtmp = "";
	$file = uc(substr($file, -3));

#checking for the right ID3 tags

	if (!$artist) {
	$artist1 = ""; if (!$album && $year) { $albtxt = "$year - "; } if ($album && $year) { $albtxt = "$album/$year - "; } if ($album && !$year) { $albtxt = "$album - "; } if (!$album && !$year) { $albtxt = ""; } $songtmp = "$song";
}
	else {
	$artist1 = "$artist"; if (!$album && $year) { $albtxt = " - $year - "; } if ($album && $year) { $albtxt = " - $album/$year - "; } if ($album && !$year) { $albtxt = " - $album - "; } if (!$album && !$year) { $albtxt = " - "; } $songtmp = "$song";
}
	#track number
	if ($track) {
		if ($track == "-1") { $tracktmp = ""; }
		else { $tracktmp = "$track - "; }
		}

#removing filenames from tracks with no ID3 tags
$songtmp =~ s/.mp3//g;
$songtmp =~ s/.ogg//g;
$songtmp =~ s/.wma//g;

#display
	if($witem)
	{
			$witem->command("me plays $artist1$albtxt$tracktmp$songtmp ($file/$length)");

	}
}
Irssi::command_bind("exaile", 'print_info');
print "Exaile script loaded.";