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