Permalink
Browse files

Add recent additions folder and add predicate to album folders.

  • Loading branch information...
1 parent 9a956c5 commit d0f6d00b834ad44f1edb5cece72f060e9290dcf7 lispnik committed Aug 26, 2010
View
@@ -11,5 +11,6 @@
<classpathentry kind="lib" path="lib/logback-core-0.9.8.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.4.3.jar"/>
<classpathentry kind="lib" path="lib/smugmug-java-api-0.6.0.jar"/>
+ <classpathentry kind="lib" path="lib/guava-r06.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
Binary file not shown.
@@ -97,4 +97,9 @@ private void maybeRefresh() {
getPassword());
}
}
+
+ public String getNickName() {
+ maybeRefresh();
+ return withPasswordResponse.getNickName();
+ }
}
@@ -18,11 +18,16 @@
*/
package net.pms.external.smugmug;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.transform;
import net.pms.PMS;
import net.pms.dlna.FeedItem;
import net.pms.dlna.virtual.VirtualFolder;
import net.pms.formats.Format;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.kallasoft.smugmug.api.json.entity.Image;
import com.kallasoft.smugmug.api.json.v1_2_1.APIVersionConstants;
import com.kallasoft.smugmug.api.json.v1_2_1.images.Get;
@@ -33,13 +38,19 @@
private final String id;
private final int albumId;
private final String albumKey;
+ private Predicate<Image> predicate;
public AlbumFolder(String id, int albumId, String albumKey, String title) {
+ this(id, albumId, albumKey, title, Predicates.<Image> alwaysTrue());
+ }
+
+ public AlbumFolder(String id, int albumId, String albumKey, String title, Predicate<Image> predicate) {
super(title, null);
// FIXME get the thumbnail for the feature photo
this.id = id;
this.albumId = albumId;
this.albumKey = albumKey;
+ this.predicate = predicate;
}
@Override
@@ -57,8 +68,14 @@ public void discoverChildren() {
PMS.error("Error getting images for album with ID " + albumId + ": " + getResponse.getError(), null);
return;
}
- for (Image image : getResponse.getImageList()) {
- FeedItem feedItem = new FeedItem(image.getFileName(), image.getLargeURL(), image.getThumbURL(), null, Format.IMAGE);
+
+ for (FeedItem feedItem : transform(
+ filter(getResponse.getImageList(), predicate),
+ new Function<Image, FeedItem>() {
+ @Override
+ public FeedItem apply(Image image) {
+ return new FeedItem(image.getFileName(), image.getLargeURL(), image.getThumbURL(), null, Format.IMAGE);
+ }})) {
addChild(feedItem);
}
}
@@ -18,13 +18,91 @@
*/
package net.pms.external.smugmug;
+import static com.google.common.collect.Iterables.filter;
+import static net.pms.external.smugmug.SmugMugPlugin.getAccount;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import net.pms.PMS;
import net.pms.dlna.virtual.VirtualFolder;
-public class RecentAdditionsFolder extends VirtualFolder {
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.kallasoft.smugmug.api.json.entity.Album;
+import com.kallasoft.smugmug.api.json.entity.Image;
+import com.kallasoft.smugmug.api.json.v1_2_1.APIVersionConstants;
+import com.kallasoft.smugmug.api.json.v1_2_1.albums.Get;
+import com.kallasoft.smugmug.api.json.v1_2_1.albums.Get.GetResponse;
+public class RecentAdditionsFolder extends VirtualFolder {
+
+ private final String accountId;
+ private final DateFormat dateFormat;
+
public RecentAdditionsFolder(String id) {
- super("Recent Addtions", null);
- // FIXME add some kind of thumb nail
+ super("Recent Photos", null);
+ this.accountId = id;
+ dateFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
}
+ @Override
+ public void discoverChildren() {
+ super.discoverChildren();
+ Account account = getAccount(accountId);
+ Get get = new Get();
+ GetResponse response = get.execute(APIVersionConstants.UNSECURE_SERVER_URL,
+ account.getApikey(),
+ account.getSessionId(),
+ true);
+ if (response.isError()) {
+ PMS.error("Error getting albums: " + response.getError(), null);
+ return;
+ }
+ final Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
+ calendar.roll(Calendar.MONTH, -1); // FIXME move this out to configuration file
+ Iterable<Album> albums = filter(response.getAlbumList(), new Predicate<Album>() {
+ @Override
+ public boolean apply(Album album) {
+ try {
+ Date date = dateFormat.parse(album.getLastUpdated());
+ return calendar.before(date);
+ } catch (Exception e) {
+ PMS.error("Error parsing last updated date: " + album.getLastUpdated(), e);
+ return false;
+ }
+ }});
+
+ final Predicate<Image> predicate = new Predicate<Image>() {
+ @Override
+ public boolean apply(Image image) {
+ try {
+ Date date = dateFormat.parse(image.getLastUpdated());
+ return calendar.before(date);
+ } catch (ParseException e) {
+ PMS.error("Error parsing image last updated date: " + image.getLastUpdated(), e);
+ return false;
+ }
+ }};
+
+ for (AlbumFolder folder : Iterables.transform(albums, new Function<Album, AlbumFolder>() {
+ @Override
+ public AlbumFolder apply(Album album) {
+ return new AlbumFolder(accountId, album.getID(), album.getAlbumKey(), album.getTitle(), predicate);
+ }})) {
+ addChild(folder);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return String.format("RecentAdditionsFolder [accountId=%s]", accountId);
+ }
}
@@ -40,10 +40,10 @@ public static Account getAccount(String id) {
public SmugMugPlugin() {
PMS.info("Loading smugmug-pms3 Plugin");
- System.err.println("smugmug-pms3 Plugin, Copyright (C) 2010 Matthew Kennedy\n"
- + "smugmug-pms3 comes with ABSOLUTELY NO WARRANTY\n"
- + "This is free software, and you are welcome to redistribute it\n"
- + "under the GNU GENERAL PUBLIC LICENSE Version 2");
+ System.err.println("** smugmug-pms3 Plugin, Copyright (C) 2010 Matthew Kennedy\n"
+ + "** smugmug-pms3 comes with ABSOLUTELY NO WARRANTY\n"
+ + "** This is free software, and you are welcome to redistribute it\n"
+ + "** under the GNU GENERAL PUBLIC LICENSE Version 2");
// FIXME allow selection of smugmug configuration through GUI
final File file = new File(System.getProperty("user.home"), ".smugmug.properties");
PMS.info("Reading account configurations from: " + file);

0 comments on commit d0f6d00

Please sign in to comment.