line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Automaton::Plugin::Filter::Unshorten; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Expansion of shortneded URLs |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
381
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
411
|
use Moo; |
|
1
|
|
|
|
|
8447
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
1519
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
25466
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
245
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub go { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
0
|
|
|
|
|
|
my $in = shift; |
15
|
0
|
|
|
|
|
|
my $bits = shift; |
16
|
0
|
|
|
|
|
|
my $d = $in->{debug}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my @patterns = ( |
19
|
|
|
|
|
|
|
"http[s]?:\/\/t.co\/.{10}", #twitter |
20
|
|
|
|
|
|
|
"http[s]?:\/\/goo.gl\/[a-z,A-Z,0-9]*", # google |
21
|
|
|
|
|
|
|
"http[s]?:\/\/bit.ly\/[a-z,A-Z,0-9]*", #http://bit.ly/1vsPSjP |
22
|
|
|
|
|
|
|
"http[s]?:\/\/bit.do\/[a-z,A-Z,0-9]*", #http://bit.do/UVBz |
23
|
|
|
|
|
|
|
"http[s]?:\/\/ow.ly\/[a-z,A-Z,0-9]*", # http://ow.ly/FiTXV |
24
|
|
|
|
|
|
|
"http[s]?:\/\/tr.im\/[a-z,A-Z,0-9]*", # https://tr.im/23498 |
25
|
|
|
|
|
|
|
"http[s]?:\/\/youtu.be\/.{11}", |
26
|
|
|
|
|
|
|
"http[s]?:\/\/t.ted.com\/.{7}", |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $pattern_string = join('|', @patterns); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
foreach my $bit (@$bits) { |
32
|
0
|
|
|
|
|
|
$bit =~ s/($pattern_string)/_unshorten($d, $1)/eg; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _unshorten { |
39
|
0
|
|
|
0
|
|
|
my $d = shift; |
40
|
0
|
|
|
|
|
|
my $input = shift; |
41
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
42
|
0
|
|
|
|
|
|
my $r = $ua->head($input); |
43
|
0
|
|
|
|
|
|
my $new_url = $r->base; |
44
|
0
|
|
|
|
|
|
_logger($d, "Expanding $input to $new_url"); |
45
|
0
|
|
|
|
|
|
return $new_url; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _logger { |
49
|
0
|
|
|
0
|
|
|
my $level = shift; |
50
|
0
|
|
|
|
|
|
my $message = shift; |
51
|
0
|
0
|
|
|
|
|
print "$message\n" if $level; |
52
|
0
|
|
|
|
|
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |