| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Image::Imgur; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mojolicious::Plugin::LinkEmbedder::Link::Image::Imgur - imgur.com image |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This class inherits from L. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
582
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Image'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 media_id |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Extracts the media_id from the url directly |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 media_url |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
URL to the image itself, extracted from the retrieved page |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 media_title |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The title of the image, extracted from the retrieved page |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 provider_name |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has media_id => sub { shift->url->path->[0] }; |
|
34
|
0
|
|
|
0
|
1
|
|
sub provider_name {'Imgur'} |
|
35
|
|
|
|
|
|
|
has [qw( media_url media_title )]; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 learn |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Gets the file imformation from the page meta information |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub learn { |
|
46
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $cb) = @_; |
|
47
|
0
|
|
|
|
|
|
my $ua = $self->{ua}; |
|
48
|
|
|
|
|
|
|
my $delay = Mojo::IOLoop->delay( |
|
49
|
|
|
|
|
|
|
sub { |
|
50
|
0
|
|
|
0
|
|
|
my $delay = shift; |
|
51
|
0
|
|
|
|
|
|
$ua->get($self->url, $delay->begin); |
|
52
|
|
|
|
|
|
|
}, |
|
53
|
|
|
|
|
|
|
sub { |
|
54
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
|
55
|
0
|
|
|
|
|
|
my $dom = $tx->res->dom; |
|
56
|
0
|
|
0
|
|
|
|
$self->media_url(Mojo::URL->new(($dom->at('meta[property="og:image"]') || {})->{content})); |
|
57
|
0
|
|
0
|
|
|
|
$self->media_title(($dom->at('meta[property="og:title"]') || {})->{content}); |
|
58
|
0
|
|
|
|
|
|
$self->$cb; |
|
59
|
|
|
|
|
|
|
}, |
|
60
|
0
|
|
|
|
|
|
); |
|
61
|
0
|
0
|
|
|
|
|
$delay->wait unless $delay->ioloop->is_running; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 to_embed |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns an img tag. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub to_embed { |
|
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
$self->tag( |
|
74
|
|
|
|
|
|
|
img => src => $self->media_url, |
|
75
|
|
|
|
|
|
|
alt => $self->media_title || $self->media_url, |
|
76
|
|
|
|
|
|
|
title => $self->media_title |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 AUTHOR |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Joel Berger - C |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |