Skip to content

Commit

Permalink
video support
Browse files Browse the repository at this point in the history
  • Loading branch information
jcodagnone committed Mar 3, 2015
1 parent ce3b49a commit 9528315
Show file tree
Hide file tree
Showing 9 changed files with 963 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Activity implements Serializable {
private Provider provider;
@JsonProperty(value = "twitter_entities")
private TwitterEntities twitterEntities;
@JsonProperty(value = "twitter_extended_entities")
private TwitterEntities twitterExtendedEntities;
private long retweetCount;
private int favoritesCount;
@JsonProperty(value = "twitter_filter_level")
Expand Down Expand Up @@ -128,6 +130,14 @@ public final void setTwitterEntities(final TwitterEntities value) {
twitterEntities = value;
}

public TwitterEntities getTwitterExtendedEntities() {
return twitterExtendedEntities;
}

public void setTwitterExtendedEntities(final TwitterEntities twitterExtendedEntities) {
this.twitterExtendedEntities = twitterExtendedEntities;
}

public final Gnip getGnip() {
if(gnip == null) {
gnip = new Gnip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ public class MediaUrls extends Urls {

@JsonProperty(value = "id_str")
private String id;
@JsonProperty(value = "source_status_id_str")
private String sourceStatusIdStr;

@JsonProperty(value = "media_url")
private String mediaUrl;
@JsonProperty("media_url_https")
private String mediaUrlHttps;
private String type;
private Sizes sizes;
@JsonProperty(value = "video_info")
private VideoInfo videoInfo;

public String getId() {
return id;
Expand Down Expand Up @@ -70,6 +75,35 @@ public void setSizes(Sizes sizes) {
this.sizes = sizes;
}


public String getSourceStatusIdStr() {
return sourceStatusIdStr;
}

public void setSourceStatusIdStr(final String sourceStatusIdStr) {
this.sourceStatusIdStr = sourceStatusIdStr;
}

public VideoInfo getVideoInfo() {
return videoInfo;
}

public void setVideoInfo(final VideoInfo videoInfo) {
this.videoInfo = videoInfo;
}

public String getMediaUrl() {
return mediaUrl;
}

public void setMediaUrl(final String mediaUrl) {
this.mediaUrl = mediaUrl;
}

public String getMediaUrlHttps() {
return mediaUrlHttps;
}

public void setMediaUrlHttps(final String mediaUrlHttps) {
this.mediaUrlHttps = mediaUrlHttps;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2011-2012 Zauber S.A. <http://www.zaubersoftware.com/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zaubersoftware.gnip4j.api.model;

import org.codehaus.jackson.annotate.JsonProperty;

public class TwitterVideoVariant {
private Integer bitrate;
@JsonProperty(value = "content_type")
private String contentType;
private String url;

public Integer getBitrate() {
return bitrate;
}

public String getContentType() {
return contentType;
}

public String getUrl() {
return url;
}

public void setBitrate(Integer bitrate) {
this.bitrate = bitrate;
}

public void setContentType(String contentType) {
this.contentType = contentType;
}

public void setUrl(String url) {
this.url = url;
}

}
11 changes: 6 additions & 5 deletions core/src/main/java/com/zaubersoftware/gnip4j/api/model/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ public void setUrl(final String value) {
public String getDisplayUrl() {
return displayUrl;
}
/**
* Sets the displayUrl.
*
* @param displayUrl <code>String</code> with the displayUrl.
*/

public void setDisplayUrl(final String displayUrl) {
this.displayUrl = displayUrl;
}

public void setIndices(List<Integer> indices) {
this.indices = indices;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2011-2012 Zauber S.A. <http://www.zaubersoftware.com/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zaubersoftware.gnip4j.api.model;

import java.util.List;

import org.codehaus.jackson.annotate.JsonProperty;

/**
* Twitter Video Info
*
*
* @author Juan F. Codagnone
* @since Mar 3, 2015
*/
public class VideoInfo {
@JsonProperty(value = "duration_millis")
private Long durationMillis;
private List<TwitterVideoVariant> variants;
@JsonProperty(value = "aspect_ratio")
private List<Integer> aspectRatio;
public Long getDurationMillis() {
return durationMillis;
}
public void setDurationMillis(final Long durationMillis) {
this.durationMillis = durationMillis;
}

public List<TwitterVideoVariant> getVariants() {
return variants;
}
public void setVariants(final List<TwitterVideoVariant> variants) {
this.variants = variants;
}
public List<Integer> getAspectRatio() {
return aspectRatio;
}
public void setAspectRatio(final List<Integer> aspectRatio) {
this.aspectRatio = aspectRatio;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.List;

import org.codehaus.jackson.JsonParseException;
Expand All @@ -36,7 +37,10 @@
import com.zaubersoftware.gnip4j.api.model.Activity;
import com.zaubersoftware.gnip4j.api.model.Geo;
import com.zaubersoftware.gnip4j.api.model.MatchingRules;
import com.zaubersoftware.gnip4j.api.model.MediaUrls;
import com.zaubersoftware.gnip4j.api.model.Point;
import com.zaubersoftware.gnip4j.api.model.TwitterVideoVariant;
import com.zaubersoftware.gnip4j.api.model.VideoInfo;


/**
Expand Down Expand Up @@ -182,4 +186,59 @@ public void testFavoriteCountMissing() throws Exception {
is.close();
}
}

/** test a complete unmarshal from the json */
@Test
public void testAnimatedGif() throws Exception {
final InputStream is = getClass().getClassLoader().getResourceAsStream(
"com/zaubersoftware/gnip4j/payload/animated_gif.js");
try {
final JsonParser parser = mapper.getJsonFactory().createJsonParser(is);
final Activity activity = parser.readValueAs(Activity.class);

assertNotNull(activity.getTwitterExtendedEntities());
assertNotNull(activity.getTwitterExtendedEntities());
assertEquals(1, activity.getTwitterExtendedEntities().getMediaUrls().size());
MediaUrls mediaUrls = activity.getTwitterExtendedEntities().getMediaUrls().get(0);

final VideoInfo videoInfo = mediaUrls.getVideoInfo();
assertNull(videoInfo.getDurationMillis());
assertEquals(Arrays.asList(25, 14), videoInfo.getAspectRatio());
assertEquals(1, videoInfo.getVariants().size());
final TwitterVideoVariant v = videoInfo.getVariants().get(0);
assertEquals(0, v.getBitrate().intValue());
assertEquals("video/mp4" , v.getContentType());
assertEquals("https://pbs.twimg.com/tweet_video/B-vFBELWoAE224Z.mp4" , v.getUrl());
} finally {
is.close();
}
}

/** test a complete unmarshal from the json */
@Test
public void testVideo() throws Exception {
final InputStream is = getClass().getClassLoader().getResourceAsStream(
"com/zaubersoftware/gnip4j/payload/video.js");
try {
final JsonParser parser = mapper.getJsonFactory().createJsonParser(is);
final Activity activity = parser.readValueAs(Activity.class);

assertNotNull(activity.getTwitterExtendedEntities());
assertNotNull(activity.getTwitterExtendedEntities());
assertEquals(1, activity.getTwitterExtendedEntities().getMediaUrls().size());
MediaUrls mediaUrls = activity.getTwitterExtendedEntities().getMediaUrls().get(0);

final VideoInfo videoInfo = mediaUrls.getVideoInfo();
assertEquals(29520L, videoInfo.getDurationMillis().longValue());
assertEquals(Arrays.asList(3, 4), videoInfo.getAspectRatio());
assertEquals(4, videoInfo.getVariants().size());
final TwitterVideoVariant v = videoInfo.getVariants().get(0);
assertEquals(320000, v.getBitrate().intValue());
assertEquals("video/mp4" , v.getContentType());
assertEquals("https://video.twimg.com/ext_tw_video/570781977240080385/pu/vid/240x320/ukdop381TJHydDNj.mp4" , v.getUrl());
} finally {
is.close();
}
}

}
Loading

0 comments on commit 9528315

Please sign in to comment.