This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
picasa user password album delay photos* |
So, for example, you might issue a command like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
picasa dburger password Honolulu 3000 *.jpg |
This would initiate an upload of all the jpg files in the current directory to my Picasa Web Albums under an album name of Honolulu with a throttling delay of 3 seconds. The picasa script, which calls my java code, is a simple script as follows:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
java -cp "/home/dburger/jars/*:/home/dburger/bin/" PicasaUploader "$@" |
And finally, the java code that does all the magic, note that you will need to compile / run against some Google Data API jar files as indicated in the comments:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gdata.client.photos.PicasawebService; | |
import com.google.gdata.data.appsforyourdomain.provisioning.UserFeed; | |
import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry; | |
import com.google.gdata.data.PlainTextConstruct; | |
import com.google.gdata.data.media.MediaFileSource; | |
import com.google.gdata.data.photos.AlbumEntry; | |
import com.google.gdata.data.photos.PhotoEntry; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
// compile: javac -classpath "/home/dburger/jars/*" PicasaUploader.java | |
// execute: java -classpath "/home/dburger/jars/*:." PicasaUploader | |
public class PicasaUploader { | |
public static final String APP = "loosedog@gmail.com-picasa-uploader"; | |
public static final String BASE_URL = | |
"http://picasaweb.google.com/data/feed/api/user/"; | |
public static void main(String[] args) throws Exception { | |
if (args.length < 5) bail(); | |
String user = args[0]; | |
String pass = args[1]; | |
String album = args[2]; | |
int delay = 0; | |
try { | |
delay = Integer.parseInt(args[3]); | |
} catch (NumberFormatException exc) { | |
bail(); | |
} | |
PicasawebService service = new PicasawebService(APP); | |
service.setUserCredentials(user, pass); | |
if (!albumExists(album, user, service)) createAlbum(album, user, service); | |
URL albumUrl = new URL(BASE_URL + user + "/album/" + album); | |
for (int i = 4; i < args.length; i++) { | |
String file = args[i]; | |
MediaFileSource media = new MediaFileSource(new File(file), "image/jpeg"); | |
System.out.print("file: " + file); | |
PhotoEntry retPhoto = service.insert(albumUrl, PhotoEntry.class, media); | |
System.out.println(" complete."); | |
Thread.sleep(delay); | |
} | |
} | |
private static boolean albumExists(String album, | |
String user,PicasawebService service) throws Exception { | |
URL albumsUrl = new URL(BASE_URL + user + "?kind=album"); | |
UserFeed userFeed = service.getFeed(albumsUrl, UserFeed.class); | |
for (UserEntry ue : userFeed.getEntries()) { | |
if (ue.getTitle().getPlainText().equals(album)) return true; | |
} | |
return false; | |
} | |
private static AlbumEntry createAlbum(String album, String user, | |
PicasawebService service) throws Exception { | |
URL postUrl = new URL(BASE_URL + user); | |
AlbumEntry entry = new AlbumEntry(); | |
entry.setTitle(new PlainTextConstruct(album)); | |
return service.insert(postUrl, entry); | |
} | |
public static void bail() { | |
System.err.println(usage()); | |
System.exit(1); | |
} | |
public static String usage() { | |
return "provide arguments: user password album delay photos*"; | |
} | |
} |
Would you mind if I ported this to a different language and released that under an Open Source license?
ReplyDeleteSure, go ahead.
ReplyDeleteThis sounds like EXACTLY what I need, but I don't know where to begin to get this to work. Are there more detailed installation instructions somewhere?
ReplyDeleteSure - email me direct if you don't know how to set this up with Java - I'll help you out.
ReplyDeleteinspired by your post I've tried to implement the same in Python (I feel it is more suitable for writing command line scripts than Java) and it works nice. There are also nice Getting Started guides for google-data bindings.
ReplyDeleteIt is such a joy compared to the last attempt to build command line uploader for facebook.
I want to do it under windows, but I don't know how to do it. Do you have this code compiled?
ReplyDeleteit's possible to have all the necessary into one only .jar?
Thanks!!!
Juan
I've taken a broadly similar approach in Python which (should be) cross platform compatible. It certainly works on Linux
ReplyDeletehttps://github.com/leocrawford/picasawebsync
The upload works fairly well, and the download and sync are well on their way