From d53a283b8882012999e53c693871acf64e8fb7ef Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 10 Mar 2014 00:40:03 +0200 Subject: [PATCH] Import App::XMMS2::Notifier 0.001 --- Changes | 2 + MANIFEST | 7 ++ Makefile.PL | 14 ++++ README | 33 ++++++++ lib/App/XMMS2/Notifier.pm | 162 ++++++++++++++++++++++++++++++++++++++ t/test.t | 14 ++++ xmms2-notifier | 101 ++++++++++++++++++++++++ 7 files changed, 333 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/App/XMMS2/Notifier.pm create mode 100644 t/test.t create mode 100755 xmms2-notifier diff --git a/Changes b/Changes new file mode 100644 index 0000000..f30994e --- /dev/null +++ b/Changes @@ -0,0 +1,2 @@ +App::XMMS2::Notifier (0.001) + * Initial release diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..8e0b3f4 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,7 @@ +Changes +Makefile.PL +MANIFEST +README +t/test.t +lib/App/XMMS2/Notifier.pm +xmms2-notifier diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..ab6fc11 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,14 @@ +use 5.014002; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'App::XMMS2::Notifier', + VERSION_FROM => 'lib/App/XMMS2/Notifier.pm', + PREREQ_PM => { + 'Audio::XMMSClient' => 0.03, + 'Gtk2::Notify' => 0.05, + 'Getopt::Long' => 0}, + ABSTRACT_FROM => 'lib/App/XMMS2/Notifier.pm', + AUTHOR => 'Marius Gavrilescu ', + EXE_FILES => ['xmms2-notifier'], +); diff --git a/README b/README new file mode 100644 index 0000000..82063f0 --- /dev/null +++ b/README @@ -0,0 +1,33 @@ +App-XMMS2-Notifier version 0.001 +=============================== + +xmms2-notifier is a script which shows libnotify notifications when +the song is changed and when the playback is started/resumed. + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires these other modules and libraries: + + * Audio::XMMSClient + * Gtk2::Notify + +COPYRIGHT AND LICENCE + +Put the correct copyright and licence information here. + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. + + diff --git a/lib/App/XMMS2/Notifier.pm b/lib/App/XMMS2/Notifier.pm new file mode 100644 index 0000000..430e9a6 --- /dev/null +++ b/lib/App/XMMS2/Notifier.pm @@ -0,0 +1,162 @@ +package App::XMMS2::Notifier 0.001; +use v5.14; +use warnings; + +use Audio::XMMSClient 0.03; +use Gtk2::Notify 0.05 -init,'xmms2-notifyd'; + +use Getopt::Long; + +use constant CONVERSION_SPECIFIERS => qw/bitrate date sample_format url id channels samplerate tracknr genre artist album title/; + +################################################## + +my $use_libnotify = 1; +my $use_libpurple; +my $format = '$artist - $title'; + +GetOptions ( + "libnotify!" => \$use_libnotify, + "libpurple!" => \$use_libpurple, + "format=s" => \$format, +); + +my $xmms = Audio::XMMSClient->new('xmms2-notifyd'); +my $notify = Gtk2::Notify->new(''); + +$notify->set_timeout(3000); + +################################################## + +sub notify_libnotify{ + $notify->update($_[0]); + $notify->show; +} + +sub notify{ + my $id=$xmms->playback_current_id->wait->value or return; + my $minfo=$xmms->medialib_get_info($id)->wait->value; + + my %metadata = map { $_ => exists $minfo->{$_} ? (values $minfo->{$_})[0] : undef } CONVERSION_SPECIFIERS; + my $str=$format; + $str =~ s/\$$_/$metadata{$_}/g for keys %metadata; + + notify_libnotify $str if $use_libnotify; +# notify_libpurple $str if $use_libpurple; +} + +sub on_playback_current_id { + notify; + $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id); +} + +sub on_playback_status { + notify if $xmms->playback_status->wait->value == 1; # 1 means playing, 2 means paused + $xmms->broadcast_playback_status->notifier_set(\&on_playback_status); +} + +sub run { + while(1){ + last if ($xmms->connect); + sleep 1 + } + + $xmms->broadcast_playback_current_id->notifier_set(\&on_playback_current_id); + $xmms->broadcast_playback_status->notifier_set(\&on_playback_status); + $xmms->loop +} + +1 + +__END__ + +=head1 NAME + +App::XMMS2::Notifier - script which notifies you what xmms2 is playing + +=head1 SYNOPSIS + + # Shows libnotify notifications e.g. "Silence - Cellule" + xmms2-notifier + + # Shows libnotify notifications e.g. "Cellule by Silence (L'autre endroit), year 2005, genre Electro" + xmms2-notifier --format="$title by $artist ($album), year $date, genre $genre" + +=head1 DESCRIPTION + +xmms2-notifier is a script which shows libnotify notifications when +the song is changed and when the playback is started/resumed. + +You can control the notification format with the B<--format> argument. +The following strings are replaced: + +=over + +=item $bitrate + +The song bitrate, in bits/s. Example: 785104 + +=item $date + +Usually the year the song was published. Example: 2005 + +=item $sample_format + +The format of each sample. Example: S16 + +=item $url + +An URL that points to the song. Example: file:///ext/Music/Silence+-+Cellule.flac + +=item $id + +The XMMS2 id of the song. Example: 498 + +=item $channels + +The number of channels the song has. Example: 2 + +=item $samplerate + +The sample rate of the song, in Hz. Example: 44100 + +=item $tracknr + +The track number in the album. Example: 1 + +=item $genre + +The genre of the song. Example: Electro + +=item $artist + +The artist/band. Example: Silence + +=item $album + +The album the song is from. Example: L'autre endroit + +=item $title + +The song title. Example: Cellule + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/t/test.t b/t/test.t new file mode 100644 index 0000000..1d2c8a5 --- /dev/null +++ b/t/test.t @@ -0,0 +1,14 @@ +#!/usr/bin/perl -w +use v5.14; + +use Test::More tests => 3; +BEGIN { use_ok('App::XMMS2::Notifier') }; + +######################### + +can_ok('App::XMMS2::Notifier', qw/run notify_libnotify/); + +TODO: { + local $TODO = 'libpurple notify not written yet'; + can_ok('App::XMMS2::Notifier', 'notify_libpurple'); +} diff --git a/xmms2-notifier b/xmms2-notifier new file mode 100755 index 0000000..437b681 --- /dev/null +++ b/xmms2-notifier @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w +use v5.14; +use warnings; + +use App::XMMS2::Notifier; + +App::XMMS2::Notifier->run + +__END__ + +=head1 NAME + +xmms2-notifier - script which notifies you what xmms2 is playing + +=head1 SYNOPSIS + + # Shows libnotify notifications e.g. "Silence - Cellule" + xmms2-notifier + + # Shows libnotify notifications e.g. "Cellule by Silence (L'autre endroit), year 2005, genre Electro" + xmms2-notifier --format="$title by $artist ($album), year $date, genre $genre" + +=head1 DESCRIPTION + +xmms2-notifier is a script which shows libnotify notifications when +the song is changed and when the playback is started/resumed. + +You can control the notification format with the B<--format> argument. +The following strings are replaced: + +=over + +=item $bitrate + +The song bitrate, in bits/s. Example: 785104 + +=item $date + +Usually the year the song was published. Example: 2005 + +=item $sample_format + +The format of each sample. Example: S16 + +=item $url + +An URL that points to the song. Example: file:///ext/Music/Silence+-+Cellule.flac + +=item $id + +The XMMS2 id of the song. Example: 498 + +=item $channels + +The number of channels the song has. Example: 2 + +=item $samplerate + +The sample rate of the song, in Hz. Example: 44100 + +=item $tracknr + +The track number in the album. Example: 1 + +=item $genre + +The genre of the song. Example: Electro + +=item $artist + +The artist/band. Example: Silence + +=item $album + +The album the song is from. Example: L'autre endroit + +=item $title + +The song title. Example: Cellule + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. + + +=cut + -- 2.39.2