/** * This file is a part of the Cairo-Dock project * * Copyright : (C) see the 'copyright' file. * E-mail : see the 'copyright' file. * * This program 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. * * This program 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 this program. If not, see . * * Inspired by Imgur Bash Upload Script (http://imgur.com/tools/imgurbash.sh) */ #define _BSD_SOURCE #include #include #include #include #include "applet-struct.h" #include "applet-dnd2share.h" #include "applet-backend-imgur.h" #define NB_URLS 6 static const gchar *s_UrlLabels[NB_URLS] = {N_("Direct Link"), N_("Display Image"), N_("Large"), N_("Small"), "BBCode", "HTML"}; /* Elqb97kqkIeCD33HUtBA3hhttp://i.imgur.com/Elqb97k.pnghttp://i.imgur.com/Elqb97kl.jpghttp://i.imgur.com/Elqb97ks.jpghttp://imgur.com/Elqb97khttp://imgur.com/delete/qkIeCD33HUtBA3h */ static void upload (const gchar *cFilePath, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError) { gchar *cCommand = g_strdup_printf ("curl -L --connect-timeout 5 --retry 2 --limit-rate %dk http://imgur.com/api/upload.xml -F key=b3625162d3418ac51a9ee805b1840452 -H \"Expect: \" -F image=@\"%s\"", iLimitRate, cFilePath); cd_debug ("%s", cCommand); gchar *cResult = cairo_dock_launch_command_sync (cCommand); g_free (cCommand); if (! cResult) { DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("Imgur"); return; } gchar *cHashStart = strstr (cResult, ""); if (cHashStart) { cHashStart += 12; gchar *cHashEnd = strstr (cHashStart, ""); if (cHashEnd) *cHashEnd = '\0'; } gchar *cHash = g_strdup (cHashStart); g_free (cResult); const gchar *cExt = strrchr (cFilePath, '.'); if (cExt == NULL) cExt = ""; cResultUrls[0] = g_strdup_printf ("http://i.imgur.com/%s%s", cHash, cExt); cResultUrls[1] = g_strdup_printf ("http://imgur.com/%s", cHash); cResultUrls[2] = g_strdup_printf ("http://i.imgur.com/%sl.jpg", cHash); cResultUrls[3] = g_strdup_printf ("http://i.imgur.com/%ss.jpg", cHash); cResultUrls[4] = g_strdup_printf ("[URL=http://imgur.com/%s][IMG]http://i.imgur.com/%s%s[/IMG][/URL]", cHash, cHash, cExt); cResultUrls[5] = g_strdup_printf ("", cHash, cHash, cExt); } void cd_dnd2share_register_imgur_backend (void) { cd_dnd2share_register_new_backend (CD_TYPE_IMAGE, "Imgur.com", NB_URLS, s_UrlLabels, 0, upload); }