Welcome in Xesam-Perl

This is the xesam-perl homepage.

Here you can find informations about xesam-perl, a Perl binding for Xesam metadata providers: using this classes it is easier to trasparently access informations from common desktop trackers, execute granular searches for files, and retrieve addictional metadata.

Downloads

All releases of xesam-perl are available here.

This code is released under the GPLv3 license: just download it and use it to enhance your free applications for the Linux desktop!

How to use

To use xesam-perl you need above all the DBus binding for Perl, plus some other common (and probably already installed on your system) classes described in the README file shipped together every release.

At the current time the package contains just an helper to build complex query, and to obtain a valid XML request to submit the provider.

The following complete program looks for all files related to "Florida" using the User Language wrapper, and print out paths for matching files.

use Net::DBus::Reactor;
use Net::DBus;
use Xesam::Query;

use strict;

my $reactor = Net::DBus::Reactor->main();

# Opens connection to the Xesam provider

my $bus = Net::DBus->session;
my $xesam = $bus->get_service("org.freedesktop.xesam.searcher");
my $manager = $xesam->get_object("/org/freedesktop/xesam/searcher/main", "org.freedesktop.xesam.Search");
my $session = $manager->NewSession();

# Build a query

my $query = Xesam::Query->new_user_query("Florida");
my $search = $manager->NewSearch($session, $query->get_xml());

# Hooks handling signals

$manager->connect_to_signal("HitsAdded" => sub {
	my $num = $manager->GetHitCount ( $search );
	my $hits = $manager->GetHits ( $search, $num );

	foreach my $hit (@$hits) {
		foreach my $value (@$hit) {
			printf($value . "\n");
		}
	}
});
$manager->connect_to_signal("SearchDone" => sub {
	$manager->CloseSearch($search);
	$manager->CloseSession($session);
	$reactor->shutdown();
});

# Execute search

$manager->StartSearch($search);
$reactor->run();
		

A more complex query, untapping full Query Language of Xesam, may be built using the new_query() function, which accepts different combinations as input.

# Retrieve documents with the word "Alaska" in title
my $query = Xesam::Query->new_query(\"xesam:title", Xesam::Query::CONTAINS, {type => "string", value => "Alaska"});
		
# Retrieve all PDF documents and PNG images
my @values = ( {type => "string", value => "application/pdf"}, {type => "string", value => "image/png"} );
my $query = Xesam::Query->new_query(\"xesam:mimeType", Xesam::Query::IN_SET, \@values);
		
# Retrieve all MP3s with "Hawaii" in title or album's name

my $song = Xesam::Query->new_query(\"xesam:mimeType",
                                   Xesam::Query::EQUALS,
                                   {type => "string", value => "audio/mp3"});
my $title = Xesam::Query->new_query(\"xesam:title",
                                    Xesam::Query::CONTAINS,
                                    {type => "string", value => "Hawaii"});
my $album = Xesam::Query->new_query(\"xesam:album",
                                    Xesam::Query::CONTAINS,
                                    {type => "string", value => "Hawaii"});

$song->chain_and($title->chain_or($album));
		
# Different and more efficient version for the previous

my $song = Xesam::Query->new_query(\"xesam:mimeType",
                                   Xesam::Query::EQUALS,
                                   {type => "string", value => "audio/mp3"});

my @fields = ("xesam:title", "xesam:album");
my $title = Xesam::Query->new_query(\@fields,
                                    Xesam::Query::CONTAINS,
                                    {type => "string", value => "Hawaii"});

$song->chain_and($title);
		

A complete list of all operators and combinations of input for new_query() is provided in README file attached to the package.

Getting involved

xesam-perl is freesoftware, and you can contribute the development with bug reports and feature requests.

A mailing list is also activated, you can subscribe here.