root/branches/feature-server/plagger/lib/Plagger/Plugin/Filter/iSightEnclosure.pm

Revision 1286 (checked in by ko, 5 years ago)

Added Filter::iSightEnclosure

Line 
1 package Plagger::Plugin::Filter::iSightEnclosure;
2 use strict;
3 use base qw( Plagger::Plugin );
4 use File::Temp qw(tempdir);
5
6 sub register {
7     my($self, $context) = @_;
8     $context->register_hook(
9         $self,
10         'aggregator.finalize' => \&shutter,
11         'update.entry.fixup' => \&filter,
12         'update.fixup' => \&cleanup,
13     );
14 }
15
16 sub rule_hook { 'update.entry.fixup' }
17
18 sub shutter {
19     my($self, $context) = @_;
20
21     $self->{dir} = tempdir( CLEANUP => 1 ) or $context->log(error => "tmpdir $!");
22     $self->{file} = $self->{dir} . '/isight.jpg';
23     system($self->conf->{isightcapture} . ' ' . $self->{file});
24     $self->{size} = (stat($self->{file}))[7];
25 }
26
27 sub filter {
28     my($self, $context, $args) = @_;
29
30     my $enclosure = Plagger::Enclosure->new;
31     $enclosure->url($self->{file});
32     $enclosure->local_path($self->{file});
33     $enclosure->length($self->{size});
34     $enclosure->auto_set_type;
35     $enclosure->is_inline(1) if $self->conf->{inline};
36     $args->{entry}->add_enclosure($enclosure);
37 }
38
39 sub cleanup {
40     my($self, $context) = @_;
41     rmdir(delete $self->{dir}) if $self->{dir};
42 }
43
44 1;
45
46 __END__
47
48 =head1 NAME
49
50 Plagger::Plugin::Filter::iSightEnclosure - add emclosure from iSight
51
52 =head1 SYNOPSIS
53
54   - module: Filter::iSightEnclosure
55     config:
56       iniline: 0
57       isightcapture: /User/yappo/bin/isightcapture
58
59 =head1 DESCRIPTION
60
61 add emclosure from iSight.
62 This uses isightcapture. get it from L<http://www.intergalactic.de/hacks.html>.
63
64 =head1 AUTHOR
65
66 Kazuhiro Osawa
67
68 =head1 SEE ALSO
69
70 L<Plagger>, L<http://www.intergalactic.de/hacks.html>
71
72 =cut
73
Note: See TracBrowser for help on using the browser.