| 1 |
package Plagger::Plugin::Notify::Audio; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use MP3::Info; |
|---|
| 6 |
|
|---|
| 7 |
sub init { |
|---|
| 8 |
my $self = shift; |
|---|
| 9 |
$self->SUPER::init(@_); |
|---|
| 10 |
|
|---|
| 11 |
my $player = $self->conf->{player} || $^O; |
|---|
| 12 |
my $class = 'Plagger::Plugin::Notify::Audio::' . $player; |
|---|
| 13 |
eval "require $class;"; |
|---|
| 14 |
if ($@) { |
|---|
| 15 |
Plagger->context->error("Notify plugin doesn't run on your platform $player: $@"); |
|---|
| 16 |
} |
|---|
| 17 |
bless $self, $class; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
sub register { |
|---|
| 21 |
my($self, $context) = @_; |
|---|
| 22 |
$context->register_hook( |
|---|
| 23 |
$self, |
|---|
| 24 |
'publish.entry' => \&update, |
|---|
| 25 |
'publish.finalize' => \&finalize, |
|---|
| 26 |
); |
|---|
| 27 |
$self->{enclosures} = [ ]; |
|---|
| 28 |
$self->{count} = 0; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
sub update { |
|---|
| 32 |
my($self, $context, $args) = @_; |
|---|
| 33 |
|
|---|
| 34 |
if ($self->conf->{play_enclosures}) { |
|---|
| 35 |
push @{$self->{enclosures}}, grep $_->local_path, $args->{entry}->enclosures; |
|---|
| 36 |
} else { |
|---|
| 37 |
$self->{count}++; |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
sub finalize { |
|---|
| 42 |
my($self, $context, $args) = @_; |
|---|
| 43 |
|
|---|
| 44 |
if ($self->{count}) { |
|---|
| 45 |
$self->log(info => "Play " . $self->conf->{filename}); |
|---|
| 46 |
return $self->play($self->conf->{filename}); |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
for my $enclosure (@{$self->{enclosures}}) { |
|---|
| 50 |
|
|---|
| 51 |
my $info = eval { MP3::Info->new($enclosure->local_path) }; |
|---|
| 52 |
my $length = $info ? $info->secs : undef; |
|---|
| 53 |
$self->log(info => "Play " . $enclosure->local_path . ($length ? " for $length seconds" : "")); |
|---|
| 54 |
$self->play($enclosure->local_path, $length); |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
sub play { |
|---|
| 59 |
my($self, $filename) = @_; |
|---|
| 60 |
$self->log(warn => "Subclass should override this"); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
1; |
|---|
| 64 |
__END__ |
|---|
| 65 |
|
|---|
| 66 |
=head1 NAME |
|---|
| 67 |
|
|---|
| 68 |
Plagger::Plugin::Notify::Audio - Notifies feed updates via audio file |
|---|
| 69 |
|
|---|
| 70 |
=head1 SYNOPSIS |
|---|
| 71 |
|
|---|
| 72 |
# play single file when feeds are updated |
|---|
| 73 |
- module: Notify::Audio |
|---|
| 74 |
config: |
|---|
| 75 |
filename: /path/to/foo.wav |
|---|
| 76 |
|
|---|
| 77 |
# play enclosures downloaded with Filter::FetchEnclosure |
|---|
| 78 |
- module: Notify::Audio |
|---|
| 79 |
config: |
|---|
| 80 |
play_enclosures: 1 |
|---|
| 81 |
|
|---|
| 82 |
=head1 DESCRIPTION |
|---|
| 83 |
|
|---|
| 84 |
This plugin plays audio file when you've got feed updates. |
|---|
| 85 |
|
|---|
| 86 |
=head1 CONFIG |
|---|
| 87 |
|
|---|
| 88 |
=over 4 |
|---|
| 89 |
|
|---|
| 90 |
=item filename |
|---|
| 91 |
|
|---|
| 92 |
Audio filename to play. Required, if you don't set I<play_enclosures>. |
|---|
| 93 |
|
|---|
| 94 |
=item play_enclosures |
|---|
| 95 |
|
|---|
| 96 |
If set, it'll play local enclosure file which are downloaded via |
|---|
| 97 |
Filter::FetchEnclosure, if any. |
|---|
| 98 |
|
|---|
| 99 |
=back |
|---|
| 100 |
|
|---|
| 101 |
=head1 AUTHOR |
|---|
| 102 |
|
|---|
| 103 |
Tatsuhiko Miyagawa |
|---|
| 104 |
|
|---|
| 105 |
=head1 SEE ALSO |
|---|
| 106 |
|
|---|
| 107 |
L<Plagger> |
|---|
| 108 |
|
|---|
| 109 |
=cut |
|---|