line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Video::Flvstreamer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30588
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
2430
|
use IPC::Run qw/run timeout/; |
|
1
|
|
|
|
|
79456
|
|
|
1
|
|
|
|
|
811
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Video::Flvstreamer - An OO interface to flvstreamer |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.04 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
An interface to flvstreamer: a commandline video stream ripping application |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
http://savannah.nongnu.org/projects/flvstreamer |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Video::Flvstreamer; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $flv = Video::Flvstreamer->new(); |
30
|
|
|
|
|
|
|
$flv->get( $url, $target ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Create a new object. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $flv = Video::Flvstreamer->new(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
or |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $flv = Video::Flvstreamer->new( { flvstreamer => $path_to_flvstreamer, |
44
|
|
|
|
|
|
|
timeout => $timout_seconds, |
45
|
|
|
|
|
|
|
try => $try_times, |
46
|
|
|
|
|
|
|
socks => $socks_proxy } ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
flvstreamer is the path to your binary flvstreamer. Default: /usr/bin/flvstreamer |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
timeout is the network timeout (seconds) during streaming. Default: 10 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
try is the number of times flvstreamer should be called (with --resume) to try and complete a download, |
53
|
|
|
|
|
|
|
if errors occur. Default: 10 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
socks is the socks proxy server for flvstreamer to use if necessary |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new{ |
60
|
0
|
|
|
0
|
1
|
|
my( $class, $args ) = @_; |
61
|
0
|
|
|
|
|
|
my $self = {}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Some defaults |
64
|
0
|
|
|
|
|
|
$self->{flvstreamer} = '/usr/bin/flvstreamer'; |
65
|
0
|
|
|
|
|
|
$self->{timeout} = 10; |
66
|
0
|
|
|
|
|
|
$self->{try} = 10; |
67
|
0
|
|
|
|
|
|
$self->{debug} = undef; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
foreach( qw/flvstreamer timout socks debug/ ){ |
70
|
0
|
0
|
|
|
|
|
if( $args->{$_} ){ |
71
|
0
|
|
|
|
|
|
$self->{$_} = $args->{$_}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if( ! -e $self->{flvstreamer} ){ |
76
|
0
|
|
|
|
|
|
die( "flvstreamer is not executable or does not exist: $self->{flvstreamer}\n"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
bless $self, $class; |
80
|
0
|
|
|
|
|
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 get_raw |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$flv->get_raw( $raw_string, $target, $args ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
raw_string is a pre-formatted flvstreamer argument string. e.g. |
90
|
|
|
|
|
|
|
-r rtmp://example.org/stream |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
target is the target that the ripped stream should be saved to |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
args are the same as in the new() method, if you want to have individual settings for this get command |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
-resume and -o $target is still automatically added to the raw_string |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_raw{ |
101
|
0
|
|
|
0
|
1
|
|
my( $self, $raw, $target, $args ) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if( ! $raw ){ |
104
|
0
|
|
|
|
|
|
die( __PACKAGE__ . " no raw opts passed to get_raw" ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Allow override by args, otherwise use defaults |
108
|
0
|
|
|
|
|
|
foreach( qw/timout flvstreamer socks swfUrl pageUrl/ ){ |
109
|
0
|
0
|
0
|
|
|
|
if( ! $args->{$_} && $self->{$_} ){ |
110
|
0
|
|
|
|
|
|
$args->{$_} = $self->{$_}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my @cmd; |
115
|
0
|
0
|
|
|
|
|
if( ref( $raw ) eq 'ARRAY' ){ |
116
|
0
|
|
|
|
|
|
@cmd = ( $args->{flvstreamer}, @$raw, '--resume', '-q', '-o', $target ); |
117
|
|
|
|
|
|
|
}else{ |
118
|
0
|
|
|
|
|
|
@cmd = ( $args->{flvstreamer}, $raw, '--resume', '-q', '-o', $target ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Often transfer fails - retry till finished |
122
|
0
|
|
|
|
|
|
my $finished = undef; |
123
|
0
|
|
|
|
|
|
my $try = 1; |
124
|
0
|
|
|
|
|
|
my $last_size = undef; |
125
|
0
|
|
|
|
|
|
my( $out, $err ); |
126
|
|
|
|
|
|
|
TRY_DOWNLOAD: |
127
|
0
|
|
0
|
|
|
|
while( ! $finished and $try <= $self->{try} ){ |
128
|
|
|
|
|
|
|
# Out/Err don't seem to be used by flvstreamer in -q mode... |
129
|
0
|
0
|
|
|
|
|
if( $self->{debug} ){ |
130
|
0
|
|
|
|
|
|
printf( __PACKAGE__ . "->get_raw : try=%03u, cmd = %s\n", $try, join( ' ', @cmd ) ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
if( run( \@cmd, undef, \$out, \$err ) ){ |
|
|
0
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$finished = 1; |
135
|
|
|
|
|
|
|
}elsif( $err ){ |
136
|
0
|
|
|
|
|
|
last TRY_DOWNLOAD; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
# Try again. The return value is stored in $? |
139
|
0
|
|
|
|
|
|
$try++; |
140
|
|
|
|
|
|
|
} |
141
|
0
|
0
|
|
|
|
|
if( ! $finished ){ |
142
|
0
|
|
|
|
|
|
die( "I tried $try times, but couldn't complete download.\nCommand: " . |
143
|
|
|
|
|
|
|
join( ' ', @cmd ) . |
144
|
|
|
|
|
|
|
"\nLast Return code: $?\n" . |
145
|
|
|
|
|
|
|
"Last StdErr: $err\n" . |
146
|
|
|
|
|
|
|
"Last StdOut: $out\n" ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 get |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$flv->get( $url, $target, $args ); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
url is the source stream, e.g. rtmp://example.org/stream |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
target is the target that the ripped stream should be saved to |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
args are the same as in the new() method, if you want to have individual settings for this get command |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
sub get{ |
162
|
0
|
|
|
0
|
1
|
|
my( $self, $url, $target, $args ) = @_; |
163
|
0
|
0
|
|
|
|
|
if( ! $url ){ |
164
|
0
|
|
|
|
|
|
die( __PACKAGE__ . " cannot get without a url\n" ); |
165
|
|
|
|
|
|
|
} |
166
|
0
|
0
|
|
|
|
|
if( $url !~ m/^rtmp\:\/\// ){ |
167
|
0
|
|
|
|
|
|
die( __PACKAGE__ . " invalid protocol (not rtmp): $url\n" ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Allow override by args, otherwise use defaults |
171
|
0
|
|
|
|
|
|
foreach( qw/timout flvstreamer socks swfUrl pageUrl/ ){ |
172
|
0
|
0
|
0
|
|
|
|
if( ! $args->{$_} && $self->{$_} ){ |
173
|
0
|
|
|
|
|
|
$args->{$_} = $self->{$_}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my @flv_opts = ( '--rtmp', $url ); |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
foreach( qw/swfUrl pageUrl timeout/ ){ |
180
|
0
|
0
|
|
|
|
|
if( $args->{$_} ){ |
181
|
0
|
|
|
|
|
|
push( @flv_opts, '--' . $_ ); |
182
|
0
|
|
|
|
|
|
push( @flv_opts, $args->{$_} ); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $self->get_raw( \@flv_opts, $target, $args ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Robin Clarke, C<< >> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 BUGS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
198
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
199
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 SUPPORT |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
perldoc Video::Flvstreamer |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
You can also look for information at: |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over 4 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * Repository on Github |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * CPAN Ratings |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * Search CPAN |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
L |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright 2010 Robin Clarke. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
245
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
246
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
1; # End of Video::Flvstreamer |