root/lang/perl/plagger/lib/Plagger/Plugin/Filter/FLVInfo.pm

Revision 461, 2.3 kB (checked in by otsune, 12 months ago)

lang/perl/plagger/lib/Plagger/Plugin/Filter/FLVInfo.pm: fix typo POD
lang/perl/misc/fooo_name.pl: scrape fooo.name URI

Line 
1package Plagger::Plugin::Filter::FLVInfo;
2
3use strict;
4use base qw( Plagger::Plugin );
5use Plagger::Util;
6use FLV::Info;
7
8sub register {
9    my($self, $context) = @_;
10    $context->register_hook(
11        $self,
12        'update.entry.fixup' => \&filter,
13    );
14}
15
16sub filter {
17    my($self, $context, $args) = @_;
18
19    my $entry = $args->{entry};
20
21    # XXX get info from first one only.
22    my $enclosure = $entry->enclosure;
23    if (!defined $enclosure) {
24        $context->log( error => q{Can't find an enclosure.} );
25        return;
26    }
27
28    eval { $enclosure->local_path };
29    if($@){
30        $context->log( error => q{Can't get local file.} );
31        return;
32    }
33
34    my $local_path = $enclosure->local_path;
35    if ($local_path !~ m/\.flv$/xmsg) {
36        $context->log( warn => qq{Can't get info from $local_path.} );
37        return;
38    }
39
40    $context->log( info => "Extracting video information from $local_path" );
41    my $reader = FLV::Info->new();
42    $reader->parse($enclosure->local_path);
43
44    my %info = $reader->get_info;
45    my %flvinfo;
46
47    my $height = $info{video_height} || $info{meta_height};
48    my $width  = $info{video_width}  || $info{meta_width};
49
50    %flvinfo = (
51        height => $height,
52        width  => $width,
53        aspect => ( $width/$height > 1.5 ) ? '16:9' : '4:3',
54    );
55
56    my $metadata_keys = $self->conf->{metadata};
57    $metadata_keys = [ $metadata_keys ] unless ref $metadata_keys;
58    map { $flvinfo{$_} = $info{$_} } @{$metadata_keys};
59
60    $entry->meta->{flvinfo} = \%flvinfo;
61   
62}
63
641;
65__END__
66
67=head1 NAME
68
69Plagger::Plugin::Filter::FLVInfo - Add FLV video information to entries
70
71=head1 SYNOPSIS
72
73  - module: Filter::FLVInfo
74
75  - module: Filter::FFmpeg
76    rule:
77      expression: "$args->{entry}->meta->{flvinfo}->{aspect} eq '4:3'"
78    config:
79      # Settings for videos whose aspect ratio is '4:3'
80
81  - module: Filter::FFmpeg
82    rule:
83      expression: "$args->{entry}->meta->{flvinfo}->{aspect} eq '16:9'"
84    config:
85      # Settings for videos whose aspect ratio is '16:9'
86
87=head1 DESCRIPTION
88
89This plugin extract FLV video information from enclosures, and attach it to the entry.
90
91=head1 CONFIG
92
93  - module: Filter::FLVInfo
94    config:
95      metadata:
96        - duration
97        - video_codec
98        - audio_rate
99
100=head1 AUTHOR
101
102Yohei Fushii, Masafumi Otsune
103
104=head1 SEE ALSO
105
106L<Plagger>, L<FLV::Info>
107
108=cut
Note: See TracBrowser for help on using the browser.