May 26, 2009

Upload photos to facebook from Nautilus

EDIT:
~UPDATED 15-07-2010
Added ability to create album.
Photo's will be auto-rotated if EXIF information is available.
12-JUN-2010
reworked the mechanism to work with the new FBCMD.
Does not need a manual update of albumdata file (will be handled on it's own.)

If you run this on a directory, it will upload all *.jpg files in said directory.

30-MAY-09

Fixed stupid bug where the cancelling uploaded the picture anyway.Thank you Mr. Anonymous bug reporter.

It's been a while since I've posted an update, not that I suspect that anybody missed me or anything. Nonetheless I'm throwing out an obligatory apology and the explaination for it being "been busy"

anyway this is something I whipped up today that somebody might find useful. It's a nautilus script that uploads your photos to facebook. So you can just right-click on a photo and upload it there.It's fairly basic (offers multiple uploads,album-selection, no-tagging,no caption), and once again it's not completely idiot proof so I'm not taking responsibility if you muck something up.

currently this depends on the following
  • libnotify (particularly notify-send)
  • zenity
  • imagemagick
  • fbcmd (and hence php)
fbcmd here being the facebook command-line application by Dave Tompkins, which can be found at http://fbcmd.dtompkins.com. So once you have that up and running and properly authorized (find instructions on fbcmd page)

The script needs to go into ~/.gnome2/nautilus-scripts


Next you should setup an albumid file because it's faster if you maintain a local list). Do this by running

php fbcmd.php albums | tee ~/.fbaids

if you'd rather fetch album information from facebook everytime you can replace the line "aidlist=~/.fbaids" with "aidlist=\"$(php FBCMDPATH albums)\""
that should do it.


please note that I haven't implemented a check on weather the upload was successful or not. Also there is no filetype check so be careful.

#!/bin/bash
# AUTHOR: (c) Naail Abdul Rahman (http://kudanai.blogspot.com)
# VERSION: 1.0
# LICENSE: GPL (http://www.gnu.org/licenses/gpl.html)
# REQUIRES: libnotify, zenity, FBCMD (http://fbcmd.dtompkins.com),imagemagick
# NAME:  Upload to Facebook
# DESCRIPTION: Simple nautilus script to invoke FBCMD upload functionality.
#  Currently only supports pictures.Hope to adding notes as well.
#  FBCMD is a command line interface to facebook by Dave Tompkins
 
fbcmdl=fbcmd #command to invoke fbcmd...usually just fbcmd
 
function notify() {
 notify-send -i fbnotif UPLOADING "$@"
}
 
function makealbum() {
 title=$(zenity --entry --title="Title?" --text="Enter Album Title (Required):")
 if [ -z $title ]
 then
  getaid
 fi
 
 desc=$(zenity --entry --title="Description?" \
  --text="Enter a description for the album (optional):\nLeave blank if you don't want to set a descroption")
 location=$(zenity --entry --title="Location?" \
  --text="Enter a location for the album (optional):\nLeave blank if you don't want to set a location")
 privacyOpt=$(zenity --entry --title="Privacy?" \
  --text="Who can see this album? (default:everyone)\n1.friends\n2.friends-of-friends\n3.networks\n4.everyone")
 
  case $privacyOpt in
   1) privacy="friends"
    ;;
   2) privacy="friends-of-friends"
    ;;
   3) privacy="networks"
    ;;
   4) privacy="everyone"
    ;;
   *) privacy="everyone"
    ;;
  esac
 notify "creating album $title"
 $fbcmdl addalbum "${title}" "${desc}" "${location}" $privacy
}
 
function getaid() {
 
 aid=$(zenity --entry --title="Album?" \
   --text="Enter AlbumID or #\n\nenter:\n  0 for list\n  l (low L) for latest\n a for new")
  
 if [ -z $aid ];
 then
  echo "null value for aid - quiting"
  notify "upload cancelled"
  exit
 else
  case $aid in
   0) echo "please wait, fetching album data"
    $fbcmdl albums | zenity --text-info \
       --title "album names and stuff" --width=600
    getaid
    ;;
   l) aid="latest"
    ;;
   a) makealbum
    echo "created album.."
    aid="latest"
    ;;
  esac
 fi
}
 
getaid
notify "uploading photos"
  
for arg
do
 if [ -f $arg ]
 then
  echo "adding regular file ${arg}"
  convert -auto-orient -resize '604>' "$arg" /tmp/fbuplpictmpxx.jpg
  $fbcmdl addpic /tmp/fbuplpictmpxx.jpg $aid
 elif [ -d $arg ]
 then
  echo "uploading directory ${arg}"
  $fbcmdl addpicd $arg $aid
 fi
done
 
notify "upload finished"
exit

12 Comments:

Anonymous said...

why do you geeks always have these weird complicated shit? why can't you just make windows program?

Anonymous said...

excellent

Anonymous said...

dude thanks so much! (ubuntuforums)

OrganicPanda said...

Hey,

I don't know if something has changed on fbcmd's part but this wasn't working for me. fbcmd was expecting 1 file at a time so I've re-written the script to suit myself a bit better. Works good for me on Ubuntu 9.04.

http://organicpanda.org/bits-n-junk/facebook-upload

Enjoy

SoE said...

glad you found it useful OrganicPanda! (cool name btw)

I looked through your modifications and they look good. I had originally intended to grab the albumID's on-the-fly as well but decided that it would be too slow.

to each their own eh? this works for me that works for you hehe...

Arturo Torres Sánchez said...

“Fixed stupid bug where the cancelling uploaded the picture anyway.Thank you Mr. Anonymous bug reporter.”


I still have that bug. How can I fix it?

Anonymous said...

Hi,

The modified script is not avalaible anymore, does anyone still have it ?
Is it possible to use your script to fill an "howto" page on ubuntu-fr's wiki ?

Thanks,

Cédric

Tim said...

not working for me. :/ is there any way to execute via command line to see what the problem is?

SoE said...

gah...this is badly in need of an update.

@timyes you can execute it via cl..just run

./script.pl imagename

@Ilhuıtemoc uhh.... I'll have to get back to you on that one there.

@cedric: Sorry dude I don't have panda's code either. Maybe you can try getting in touch with him directly? and by all means... use the code as you wish.

SoE said...

heads up. I update the script last night. Should fix up most of the problems. Let me know if you have issues.

Anonymous said...

It won't pull down my albums. Is that why the script won't finish?

Anonymous said...

@Anonymous: maybe. You should update FBCMD, and then try using it by itself to test if its working and then use the script.

Post a Comment