Skip to content

Commit 0e7fb8c

Browse files
author
boncey
committed
Add new sizes and fix some tests
1 parent cb8c967 commit 0e7fb8c

17 files changed

Lines changed: 360 additions & 108 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<rsp stat="ok">
3+
<sizes canblog="1" canprint="0" candownload="0">
4+
<size label="Square" width="75" height="75" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_s.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/sq/" media="photo" />
5+
<size label="Large Square" width="150" height="150" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_q.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/q/" media="photo" />
6+
<size label="Thumbnail" width="100" height="46" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_t.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/t/" media="photo" />
7+
<size label="Small" width="240" height="111" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_m.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/s/" media="photo" />
8+
<size label="Small 320" width="320" height="148" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_n.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/n/" media="photo" />
9+
<size label="Medium" width="500" height="232" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/m/" media="photo" />
10+
<size label="Medium 640" width="640" height="297" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_z.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/z/" media="photo" />
11+
<size label="Medium 800" width="800" height="371" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_c.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/c/" media="photo" />
12+
<size label="Large" width="1024" height="475" source="http://farm8.staticflickr.com/7444/9232046055_1b83d6ac99_b.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/l/" media="photo" />
13+
<size label="Large 1600" width="1600" height="742" source="http://farm8.staticflickr.com/7444/9232046055_01da35ed4f_h.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/h/" media="photo" />
14+
<size label="Large 2048" width="2048" height="949" source="http://farm8.staticflickr.com/7444/9232046055_0ce35ecc61_k.jpg" url="http://www.flickr.com/photos/watcher24/9232046055/sizes/k/" media="photo" />
15+
</sizes>
16+
</rsp>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<rsp stat="ok">
3+
<sizes canblog="1" canprint="1" candownload="1">
4+
<size label="Square" width="75" height="75" source="http://farm4.staticflickr.com/3029/2873640658_771e573639_s.jpg" url="http://www.flickr.com/photos/boncey/2873640658/sizes/sq/" media="photo" />
5+
<size label="Large Square" width="150" height="150" source="http://farm4.staticflickr.com/3029/2873640658_771e573639_q.jpg" url="http://www.flickr.com/photos/boncey/2873640658/sizes/q/" media="photo" />
6+
<size label="Thumbnail" width="100" height="75" source="http://farm4.staticflickr.com/3029/2873640658_771e573639_t.jpg" url="http://www.flickr.com/photos/boncey/2873640658/sizes/t/" media="photo" />
7+
<size label="Small" width="240" height="180" source="http://farm4.staticflickr.com/3029/2873640658_771e573639_m.jpg" url="http://www.flickr.com/photos/boncey/2873640658/sizes/s/" media="photo" />
8+
<size label="Medium" width="320" height="240" source="http://farm4.staticflickr.com/3029/2873640658_771e573639.jpg" url="http://www.flickr.com/photos/boncey/2873640658/sizes/m/" media="photo" />
9+
<size label="Original" width="320" height="240" source="http://farm4.staticflickr.com/3029/2873640658_d10823e83a_o.png" url="http://www.flickr.com/photos/boncey/2873640658/sizes/o/" media="photo" />
10+
<size label="Video Player" width="320" height="240" source="http://www.flickr.com/apps/video/stewart.swf?v=109786&photo_id=2873640658&photo_secret=771e573639" url="http://www.flickr.com/photos/boncey/2873640658/" media="video" />
11+
<size label="Site MP4" width="320" height="240" source="http://www.flickr.com/photos/boncey/2873640658/play/site/771e573639/" url="http://www.flickr.com/photos/boncey/2873640658/" media="video" />
12+
<size label="Video Original" width="320" height="240" source="http://www.flickr.com/photos/boncey/2873640658/play/orig/d10823e83a/" url="http://www.flickr.com/photos/boncey/2873640658/" media="video" />
13+
</sizes>
14+
</rsp>

Flickr4Java/doc/photo-sizes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Square
2+
Large Square
3+
Thumbnail
4+
Small
5+
Small 320
6+
Medium
7+
Medium 640
8+
Medium 800
9+
Large
10+
Large 1600
11+
Large 2048
12+

Flickr4Java/doc/video-sizes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Square
2+
Large Square
3+
Thumbnail
4+
Small
5+
Medium
6+
Original
7+
Video Player
8+
Site MP4
9+
Video Original
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
*
3+
*/
4+
package com.flickr4java.flickr.photos;
5+
6+
/**
7+
* For the media attribute returned for different photo sizes.
8+
*
9+
* @author Darren Greaves
10+
* @see Size
11+
*
12+
*/
13+
public enum Media {
14+
15+
photo, video;
16+
}

Flickr4Java/src/main/java/com/flickr4java/flickr/photos/Photo.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ protected synchronized SimpleDateFormat initialValue() {
5151

5252
private static final String LARGE_IMAGE_SUFFIX = "_b.jpg";
5353

54+
private static final String LARGE_1600_IMAGE_SUFFIX = "_h.jpg";
55+
56+
private static final String LARGE_2048_IMAGE_SUFFIX = "_k.jpg";
57+
5458
private static final String SQUARE_LARGE_IMAGE_SUFFIX = "_q.jpg";
5559

5660
private static final String SQUARE_320_IMAGE_SUFFIX = "_n.jpg";
@@ -69,6 +73,10 @@ protected synchronized SimpleDateFormat initialValue() {
6973

7074
private Size largeSize;
7175

76+
private Size large1600Size;
77+
78+
private Size large2048Size;
79+
7280
private Size originalSize;
7381

7482
private Size squareLargeSize;
@@ -79,6 +87,12 @@ protected synchronized SimpleDateFormat initialValue() {
7987

8088
private Size medium800Size;
8189

90+
private Size videoPlayer;
91+
92+
private Size siteMP4;
93+
94+
private Size videoOriginal;
95+
8296
private String id;
8397

8498
private User owner;
@@ -728,6 +742,22 @@ public String getLargeUrl() {
728742
}
729743
}
730744

745+
public String getLarge1600Url() {
746+
if (large1600Size == null) {
747+
return getBaseImageUrl() + LARGE_1600_IMAGE_SUFFIX;
748+
} else {
749+
return large1600Size.getSource();
750+
}
751+
}
752+
753+
public String getLarge2048Url() {
754+
if (large2048Size == null) {
755+
return getBaseImageUrl() + LARGE_2048_IMAGE_SUFFIX;
756+
} else {
757+
return large2048Size.getSource();
758+
}
759+
}
760+
731761
public String getSquareLargeUrl() {
732762
if (squareLargeSize == null) {
733763
return getBaseImageUrl() + SQUARE_LARGE_IMAGE_SUFFIX;
@@ -760,6 +790,30 @@ public String getMedium800Url() {
760790
}
761791
}
762792

793+
public String getVideoPlayerUrl() {
794+
if (videoPlayer == null) {
795+
return "";
796+
} else {
797+
return videoPlayer.getSource();
798+
}
799+
}
800+
801+
public String getSiteMP4Url() {
802+
if (siteMP4 == null) {
803+
return "";
804+
} else {
805+
return siteMP4.getSource();
806+
}
807+
}
808+
809+
public String getVideoOriginalUrl() {
810+
if (videoOriginal == null) {
811+
return "";
812+
} else {
813+
return videoOriginal.getSource();
814+
}
815+
}
816+
763817
/**
764818
* Get an image using the specified URL suffix.
765819
*
@@ -960,6 +1014,10 @@ public void setSizes(Collection<Size> sizes) {
9601014
mediumSize = size;
9611015
} else if (size.getLabel() == Size.LARGE) {
9621016
largeSize = size;
1017+
} else if (size.getLabel() == Size.LARGE_1600) {
1018+
large1600Size = size;
1019+
} else if (size.getLabel() == Size.LARGE_2048) {
1020+
large2048Size = size;
9631021
} else if (size.getLabel() == Size.ORIGINAL) {
9641022
originalSize = size;
9651023
} else if (size.getLabel() == Size.SQUARE_LARGE) {
@@ -970,6 +1028,12 @@ public void setSizes(Collection<Size> sizes) {
9701028
medium640Size = size;
9711029
} else if (size.getLabel() == Size.MEDIUM_800) {
9721030
medium800Size = size;
1031+
} else if (size.getLabel() == Size.VIDEO_PLAYER) {
1032+
videoPlayer = size;
1033+
} else if (size.getLabel() == Size.SITE_MP4) {
1034+
siteMP4 = size;
1035+
} else if (size.getLabel() == Size.VIDEO_ORIGINAL) {
1036+
videoOriginal = size;
9731037
}
9741038
}
9751039
}
@@ -994,6 +1058,14 @@ public Size getLargeSize() {
9941058
return largeSize;
9951059
}
9961060

1061+
public Size getLarge1600Size() {
1062+
return large1600Size;
1063+
}
1064+
1065+
public Size getLarge2048Size() {
1066+
return large2048Size;
1067+
}
1068+
9971069
public Size getOriginalSize() {
9981070
return originalSize;
9991071
}
@@ -1014,6 +1086,18 @@ public Size getMedium800Size() {
10141086
return medium800Size;
10151087
}
10161088

1089+
public Size getVideoPlayerSize() {
1090+
return videoPlayer;
1091+
}
1092+
1093+
public Size getSiteMP4Size() {
1094+
return siteMP4;
1095+
}
1096+
1097+
public Size getVideoOriginalSize() {
1098+
return videoOriginal;
1099+
}
1100+
10171101
/**
10181102
* @return the pathAlias
10191103
*/

Flickr4Java/src/main/java/com/flickr4java/flickr/photos/PhotosInterface.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
*/
44
package com.flickr4java.flickr.photos;
55

6+
import com.flickr4java.flickr.Flickr;
7+
import com.flickr4java.flickr.FlickrException;
8+
import com.flickr4java.flickr.REST;
9+
import com.flickr4java.flickr.RequestContext;
10+
import com.flickr4java.flickr.Response;
11+
import com.flickr4java.flickr.Transport;
12+
import com.flickr4java.flickr.people.User;
13+
import com.flickr4java.flickr.photos.geo.GeoInterface;
14+
import com.flickr4java.flickr.util.IOUtilities;
15+
import com.flickr4java.flickr.util.StringUtilities;
16+
import com.flickr4java.flickr.util.XMLUtilities;
17+
18+
import org.w3c.dom.Element;
19+
import org.w3c.dom.NodeList;
20+
21+
import javax.imageio.ImageIO;
22+
623
import java.awt.image.BufferedImage;
724
import java.io.IOException;
825
import java.io.InputStream;
@@ -19,24 +36,6 @@
1936
import java.util.Map;
2037
import java.util.Set;
2138

22-
import javax.imageio.ImageIO;
23-
24-
import org.w3c.dom.Element;
25-
import org.w3c.dom.NodeList;
26-
import org.xml.sax.SAXException;
27-
28-
import com.flickr4java.flickr.Flickr;
29-
import com.flickr4java.flickr.FlickrException;
30-
import com.flickr4java.flickr.REST;
31-
import com.flickr4java.flickr.RequestContext;
32-
import com.flickr4java.flickr.Response;
33-
import com.flickr4java.flickr.Transport;
34-
import com.flickr4java.flickr.people.User;
35-
import com.flickr4java.flickr.photos.geo.GeoInterface;
36-
import com.flickr4java.flickr.util.IOUtilities;
37-
import com.flickr4java.flickr.util.StringUtilities;
38-
import com.flickr4java.flickr.util.XMLUtilities;
39-
4039
/**
4140
* Interface for working with Flickr Photos.
4241
*
@@ -100,18 +99,19 @@ public class PhotosInterface {
10099
public static final String METHOD_GET_INTERESTINGNESS = "flickr.interestingness.getList";
101100

102101
private static final ThreadLocal<SimpleDateFormat> DATE_FORMATS = new ThreadLocal<SimpleDateFormat>() {
102+
@Override
103103
protected synchronized SimpleDateFormat initialValue() {
104104
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
105105
}
106106
};
107107

108108
private GeoInterface geoInterface = null;
109109

110-
private String apiKey;
110+
private final String apiKey;
111111

112-
private String sharedSecret;
112+
private final String sharedSecret;
113113

114-
private Transport transport;
114+
private final Transport transport;
115115

116116
public PhotosInterface(String apiKey, String sharedSecret, Transport transport) {
117117
this.apiKey = apiKey;
@@ -562,7 +562,7 @@ public Photo getInfo(String photoId, String secret) throws FlickrException {
562562
if (response.isError()) {
563563
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
564564
}
565-
Element photoElement = (Element) response.getPayload();
565+
Element photoElement = response.getPayload();
566566

567567
return PhotoUtils.createPhoto(photoElement);
568568
}
@@ -741,6 +741,7 @@ public Collection<Size> getSizes(String photoId, boolean sign) throws FlickrExce
741741
size.setHeight(sizeElement.getAttribute("height"));
742742
size.setSource(sizeElement.getAttribute("source"));
743743
size.setUrl(sizeElement.getAttribute("url"));
744+
size.setMedia(sizeElement.getAttribute("media"));
744745
sizes.add(size);
745746
}
746747
return sizes;
@@ -1306,7 +1307,6 @@ public void setTags(String photoId, String[] tags) throws FlickrException {
13061307
* @param id
13071308
* The ID
13081309
* @return The Photo
1309-
* @throws SAXException
13101310
*/
13111311
public Photo getPhoto(String id) throws FlickrException {
13121312
return getPhoto(id, null);
@@ -1320,7 +1320,6 @@ public Photo getPhoto(String id) throws FlickrException {
13201320
* @param secret
13211321
* The secret
13221322
* @return The Photo
1323-
* @throws SAXException
13241323
*/
13251324
public Photo getPhoto(String id, String secret) throws FlickrException {
13261325
return getInfo(id, secret);
@@ -1353,6 +1352,10 @@ public InputStream getImageAsStream(Photo photo, int size) throws FlickrExceptio
13531352
urlStr = photo.getMediumUrl();
13541353
} else if (size == Size.LARGE) {
13551354
urlStr = photo.getLargeUrl();
1355+
} else if (size == Size.LARGE_1600) {
1356+
urlStr = photo.getLarge1600Url();
1357+
} else if (size == Size.LARGE_2048) {
1358+
urlStr = photo.getLarge2048Url();
13561359
} else if (size == Size.ORIGINAL) {
13571360
urlStr = photo.getOriginalUrl();
13581361
} else if (size == Size.SQUARE_LARGE) {

Flickr4Java/src/main/java/com/flickr4java/flickr/photos/Size.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public class Size {
176176

177177
private String url;
178178

179+
private Media media;
180+
179181
public Size() {
180182

181183
}
@@ -201,7 +203,7 @@ public int getLabel() {
201203
}
202204

203205
private final List<String> lstSizes = Arrays.asList("Thumbnail", "Square", "Small", "Medium", "Large", "Original", "Square Large", "Small 320",
204-
"Medium 640", "Medium 800");
206+
"Medium 640", "Medium 800", "Large 1600", "Large 2048", "Site MP4", "Video Player", "Video Original");
205207

206208
/**
207209
* Set the String-representation of size.
@@ -299,6 +301,18 @@ public void seturl("https://github.com/techkrish/Flickr4Java/commit/String%20url") {
299301
this.url = url;
300302
}
301303

304+
public Media getMedia() {
305+
return media;
306+
}
307+
308+
public void setMedia(Media media) {
309+
this.media = media;
310+
}
311+
312+
public void setMedia(String media) {
313+
this.media = Media.valueOf(media);
314+
}
315+
302316
@Override
303317
public boolean equals(Object obj) {
304318

0 commit comments

Comments
 (0)