Support for Video; Uploader fix. · JavaLeaks/Flickr4Java@371a31b · GitHub
Skip to content

Commit 371a31b

Browse files
author
kyparikh@gmail.com
committed
Support for Video; Uploader fix.
Added support for newer Video files ( mobileMp4, hd_MP4). ( For HD video original_video is sometimes not set only HD MP4 is set by flickr). set filename for upload (so video upload will work and title will get defaulted by flickr). Added working UploadPhoto.java to add files not uploaded already.
1 parent c00ae71 commit 371a31b

13 files changed

Lines changed: 1055 additions & 26 deletions

File tree

Flickr4Java/src/examples/java/UploadPhoto.java

Lines changed: 868 additions & 0 deletions
Large diffs are not rendered by default.

Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java

Lines changed: 26 additions & 7 deletions

Flickr4Java/src/main/java/com/flickr4java/flickr/Transport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public abstract class Transport {
2020

2121
protected static final String API_HOST = "api.flickr.com";
2222

23+
/**
24+
* Host is different for upload, need to set it from Uploader.java.
25+
*/
26+
public static final String UPLOAD_API_HOST = "up.flickr.com";
27+
2328
protected static final String DEFAULT_SCHEME = "https";
2429

2530
private String transportType;

Flickr4Java/src/main/java/com/flickr4java/flickr/galleries/GalleriesInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public PhotoList<Photo> getPhotos(String galleryId, Set<String> extras, int perP
304304
User owner = new User();
305305
owner.setId(photoElement.getAttribute("owner"));
306306
photo.setOwner(owner);
307-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
307+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
308308
photo.setServer(photoElement.getAttribute("server"));
309309
photo.setFarm(photoElement.getAttribute("farm"));
310310
photo.setTitle(photoElement.getAttribute("title"));
@@ -367,7 +367,7 @@ public PhotoList<Photo> getListForPhoto(String photoId, int perPage, int page) t
367367
User owner = new User();
368368
owner.setId(photoElement.getAttribute("owner"));
369369
photo.setOwner(owner);
370-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
370+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
371371
photo.setServer(photoElement.getAttribute("server"));
372372
photo.setFarm(photoElement.getAttribute("farm"));
373373
photo.setTitle(photoElement.getAttribute("title"));

Flickr4Java/src/main/java/com/flickr4java/flickr/people/PeopleInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public PhotoList<Photo> getPhotosOf(String userId, String ownerId, Set<String> e
420420
User owner = new User();
421421
owner.setId(photoElement.getAttribute("owner"));
422422
photo.setOwner(owner);
423-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
423+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
424424
photo.setServer(photoElement.getAttribute("server"));
425425
photo.setTitle(photoElement.getAttribute("title"));
426426
photo.setPublicFlag("1".equals(photoElement.getAttribute("ispublic")));

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ protected synchronized SimpleDateFormat initialValue() {
9393

9494
private Size videoOriginal;
9595

96+
private Size mobileMp4;
97+
98+
private Size hd_MP4;
99+
96100
private String id;
97101

98102
private User owner;
@@ -824,6 +828,22 @@ public String getVideoOriginalUrl() {
824828
}
825829
}
826830

831+
public String getMobileMP4Url() {
832+
if (mobileMp4 == null) {
833+
return "";
834+
} else {
835+
return mobileMp4.getSource();
836+
}
837+
}
838+
839+
public String getHD_MP4Url() {
840+
if (hd_MP4 == null) {
841+
return "";
842+
} else {
843+
return hd_MP4.getSource();
844+
}
845+
}
846+
827847
/**
828848
* Get an image using the specified URL suffix.
829849
*
@@ -938,7 +958,7 @@ private StringBuffer getOriginalBaseImageUrl() throws FlickrException, NullPoint
938958

939959
private StringBuffer _getBaseImageUrl() {
940960
StringBuffer buffer = new StringBuffer();
941-
buffer.append("http://farm");
961+
buffer.append("https://farm");
942962
buffer.append(getFarm());
943963
buffer.append(".static.flickr.com/");
944964
buffer.append(getServer());
@@ -1045,6 +1065,12 @@ public void setSizes(Collection<Size> sizes) {
10451065
} else if (size.getLabel() == Size.VIDEO_ORIGINAL) {
10461066
videoOriginal = size;
10471067
}
1068+
else if (size.getLabel() == Size.Mobile_MP4) {
1069+
mobileMp4 = size;
1070+
}
1071+
else if (size.getLabel() == Size.HD_MP4) {
1072+
hd_MP4 = size;
1073+
}
10481074
}
10491075
}
10501076

@@ -1108,6 +1134,34 @@ public Size getVideoOriginalSize() {
11081134
return videoOriginal;
11091135
}
11101136

1137+
/**
1138+
* @return the mobileMp4
1139+
*/
1140+
public Size getMobileMp4() {
1141+
return mobileMp4;
1142+
}
1143+
1144+
/**
1145+
* @param mobileMp4 the mobileMp4 to set
1146+
*/
1147+
public void setMobileMp4(Size mobileMp4) {
1148+
this.mobileMp4 = mobileMp4;
1149+
}
1150+
1151+
/**
1152+
* @return the hd_MP4
1153+
*/
1154+
public Size getHD_MP4() {
1155+
return hd_MP4;
1156+
}
1157+
1158+
/**
1159+
* @param hd_MP4 the hd_MP4 to set
1160+
*/
1161+
public void setHd_MP4(Size hd_MP4) {
1162+
this.hd_MP4 = hd_MP4;
1163+
}
1164+
11111165
/**
11121166
* @return the pathAlias
11131167
*/

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ public static final Photo createPhoto(Element photoElement, Element defaultEleme
167167
// Searches, or other list may contain orginal_format.
168168
// If not choosen via extras, set jpg as default.
169169
try {
170-
if (photo.getOriginalFormat().equals("")) {
171-
photo.setOriginalFormat("jpg");
170+
if (photo.getOriginalFormat() == null || photo.getOriginalFormat().equals("")) {
171+
String media = photo.getMedia();
172+
if(media != null && media.equals("video"))
173+
photo.setOriginalFormat("mov"); // Currently flickr incorrectly returns original_format as jpg for movies.
174+
else
175+
photo.setOriginalFormat("jpg");
172176
}
173177
} catch (NullPointerException e) {
174178
photo.setOriginalFormat("jpg");
@@ -181,7 +185,7 @@ public static final Photo createPhoto(Element photoElement, Element defaultEleme
181185
owner.setId(getAttribute("owner", photoElement, defaultElement));
182186
owner.setUsername(getAttribute("ownername", photoElement, defaultElement));
183187
photo.setOwner(owner);
184-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
188+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
185189
} else {
186190
User owner = new User();
187191
owner.setId(ownerElement.getAttribute("nsid"));
@@ -200,14 +204,14 @@ public static final Photo createPhoto(Element photoElement, Element defaultEleme
200204
owner.setRealName(ownerElement.getAttribute("realname"));
201205
owner.setLocation(ownerElement.getAttribute("location"));
202206
photo.setOwner(owner);
203-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
207+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
204208
}
205209
} catch (IndexOutOfBoundsException e) {
206210
User owner = new User();
207211
owner.setId(photoElement.getAttribute("owner"));
208212
owner.setUsername(photoElement.getAttribute("ownername"));
209213
photo.setOwner(owner);
210-
photo.setUrl("http://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
214+
photo.setUrl("https://flickr.com/photos/" + owner.getId() + "/" + photo.getId());
211215
}
212216

213217
try {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ public Permissions getPerms(String photoId) throws FlickrException {
657657
permissions.setId(permissionsElement.getAttribute("id"));
658658
permissions.setPublicFlag("1".equals(permissionsElement.getAttribute("ispublic")));
659659
permissions.setFamilyFlag("1".equals(permissionsElement.getAttribute("isfamily")));
660-
permissions.setFriendFlag("1".equals(permissionsElement.getAttribute("isFriend")));
660+
permissions.setFriendFlag("1".equals(permissionsElement.getAttribute("isfriend")));
661661
permissions.setComment(permissionsElement.getAttribute("permcomment"));
662662
permissions.setAddmeta(permissionsElement.getAttribute("permaddmeta"));
663663
return permissions;
@@ -1368,7 +1368,19 @@ public InputStream getImageAsStream(Photo photo, int size) throws FlickrExceptio
13681368
urlStr = photo.getMedium640Url();
13691369
} else if (size == Size.MEDIUM_800) {
13701370
urlStr = photo.getMedium800Url();
1371-
} else {
1371+
} else if (size == Size.VIDEO_ORIGINAL) {
1372+
urlStr = photo.getVideoOriginalUrl();
1373+
} else if (size == Size.VIDEO_PLAYER) {
1374+
urlStr = photo.getVideoPlayerUrl();
1375+
} else if (size == Size.SITE_MP4) {
1376+
urlStr = photo.getSiteMP4Url();
1377+
}
1378+
else if(size == Size.Mobile_MP4) {
1379+
urlStr = photo.getMobileMP4Url();
1380+
}
1381+
else if(size == Size.HD_MP4) {
1382+
urlStr = photo.getHD_MP4Url();
1383+
} else {
13721384
throw new FlickrException("0", "Unknown Photo-size");
13731385
}
13741386
URL url = new URL(urlStr);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ public class Size {
165165
* @see com.flickr4java.flickr.photos.PhotosInterface#getImageAsStream(Photo, int)
166166
*/
167167
public static final int VIDEO_ORIGINAL = 14;
168+
/**
169+
* Video, the original for mobiles.
170+
*
171+
* @see com.flickr4java.flickr.photos.Size#getLabel()
172+
* @see com.flickr4java.flickr.photos.Size#setLabel(int)
173+
* @see com.flickr4java.flickr.photos.PhotosInterface#getImage(Photo, int)
174+
* @see com.flickr4java.flickr.photos.PhotosInterface#getImageAsStream(Photo, int)
175+
*/
176+
public static final int Mobile_MP4 = 15;
177+
178+
public static final int HD_MP4 = 16;
168179

169180
private int label;
170181

@@ -203,7 +214,7 @@ public int getLabel() {
203214
}
204215

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

208219
/**
209220
* Set the String-representation of size.

Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/Photoset.java

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)