Developers

How to write an upload plugin

Upload plugins need to be written in Perl. Please use the following template when writing a new upload plugin. Please note: You need to use Shutter 0.88 or higher when using this template.
 
Save it to /usr/share/shutter/resources/system/upload_plugins/upload/ when finished.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#! /usr/bin/env perl
###################################################
#
#  Copyright (C) <year> <author> <<email>>
#
#  This file is part of Shutter.
#
#  Shutter is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  Shutter is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Shutter; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
###################################################
 
package PROVIDER;                                                       #edit
 
use lib $ENV{'SHUTTER_ROOT'}.'/share/shutter/resources/modules';
 
use utf8;
use strict;
use POSIX qw/setlocale/;
use Locale::gettext;
use Glib qw/TRUE FALSE/;
use Data::Dumper;
 
use Shutter::Upload::Shared;
our @ISA = qw(Shutter::Upload::Shared);
 
my $d = Locale::gettext->domain("shutter-plugins");
$d->dir( $ENV{'SHUTTER_INTL'} );
 
my %upload_plugin_info = (
    'module'                        => "PROVIDER",                       #edit (must be the same as 'package')
    'url'                           => "http://provider.com/",           #edit (the website's url)
    'registration'                  => "http://provider.com/register",   #edit (a link to the registration page)
    'name'                          => "PROVIDER",                       #edit (the provider's name)
    'description'                   => "Upload screenshots to PROVIDER",#edit (a description of the service)
    'supports_anonymous_upload'     => TRUE,                         #TRUE if you can upload *without* username/password
    'supports_authorized_upload'    => TRUE,                         #TRUE if username/password are supported (might be in addition to anonymous_upload)
    'supports_oauth_upload'         => FALSE,                            #TRUE if OAuth is used (see Dropbox.pm as an example)
);
 
binmode( STDOUT, ":utf8" );
if ( exists $upload_plugin_info{$ARGV[ 0 ]} ) {
    print $upload_plugin_info{$ARGV[ 0 ]};
    exit;
}
 
 
#don't touch this
sub new {
    my $class = shift;
 
    #call constructor of super class (host, debug_cparam, shutter_root, gettext_object, main_gtk_window, ua)
    my $self = $class->SUPER::new( shift, shift, shift, shift, shift, shift );
 
    bless $self, $class;
    return $self;
}
 
#load some custom modules here (or do other custom stuff)  
sub init {
    my $self = shift;
 
    use JSON;                   #example1
    use LWP::UserAgent;         #example2
    use HTTP::Request::Common;  #example3
     
    return TRUE;   
}
 
#handle
sub upload {
    my ( $self, $upload_filename, $username, $password ) = @_;
 
    #store as object vars
    $self->{_filename} = $upload_filename;
    $self->{_username} = $username;
    $self->{_password} = $password;
 
    utf8::encode $upload_filename;
    utf8::encode $password;
    utf8::encode $username;
 
    #examples related to the sub 'init'
    my $json_coder = JSON::XS->new;
 
    my $browser = LWP::UserAgent->new(
        'timeout'    => 20,
        'keep_alive' => 10,
        'env_proxy'  => 1,
    );
     
    #username/password are provided
    if ( $username ne "" && $password ne "" ) {
 
        eval{
 
            ########################
            #put the login code here
            ########################
             
            #if login failed (status code == 999) => Shutter will display an appropriate message
            #unless($login == 'success'){
            #   $self->{_links}{'status'} = 999;
            #   return;
            #}
 
        };
        if($@){
            $self->{_links}{'status'} = $@;
            return %{ $self->{_links} };
        }
        if($self->{_links}{'status'} == 999){
            return %{ $self->{_links} };
        }
         
    }
     
    #upload the file
    eval{
 
        #########################
        #put the upload code here
        #########################
         
        #save all retrieved links to a hash, as an example:
        $self->{_links}->{'direct_link'} = 'mylink1';
        $self->{_links}->{'short_link'} = 'mylink2';
        $self->{_links}->{'bbcode'} = 'mylink3';
 
        #set success code (200)
        $self->{_links}{'status'} = 200;
         
    };
    if($@){
        $self->{_links}{'status'} = $@;
    }
     
    #and return links
    return %{ $self->{_links} };
}
 
 
#you are free to implement some custom subs here, but please make sure they don't interfere with Shutter's subs
#hence, please follow this naming convention: _<provider>_sub (e.g. _imageshack_convert_x_to_y)
 
 
1;

 

Don’t hesitate to ask if you need any further help.