Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Variant media field #404

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/io/github/redouane59/twitter/TwitterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ public class TwitterClient implements ITwitterClientV1, ITwitterClientV2, ITwitt
public static final String ALL_USER_FIELDS =
"id,created_at,entities,username,name,location,url,verified,profile_image_url,public_metrics,pinned_tweet_id,description,protected";
public static final String MEDIA_FIELD = "media.fields";
public static final String
ALL_MEDIA_FIELDS =
"duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text";
public static final String ALL_MEDIA_FIELDS =
"duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text,variants";
public static final String SPACE_FIELDS = "space.fields";
public static final String
ALL_SPACE_FIELDS =
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ public static class MediaEntityV2 implements MediaEntity {
private String previewImageUrl;
@JsonProperty("public_metrics")
private MediaPublicMetricsDTO publicMetrics;
@JsonProperty("variants")
private List<Variant> variants;
@JsonProperty("alt_text")
private String altText;

Expand Down Expand Up @@ -565,4 +567,18 @@ public static class MediaPublicMetricsDTO {
@JsonProperty("view_count")
private int viewCount;
}

@Getter
@Setter
public static class Variant {

@JsonProperty("bit_rate")
private int bitRate;

@JsonProperty("content_type")
private String contentType;

@JsonProperty("url")
private String url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import io.github.redouane59.twitter.dto.tweet.Tweet;
import io.github.redouane59.twitter.dto.tweet.TweetList;
import io.github.redouane59.twitter.dto.tweet.TweetV2.MediaEntityV2;
import io.github.redouane59.twitter.dto.tweet.TweetV2.Variant;
import io.github.redouane59.twitter.dto.user.User;
import io.github.redouane59.twitter.helpers.ConverterHelper;
import io.github.redouane59.twitter.helpers.JsonHelper;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.Test;

public class TweetListDeserializerTest {
Expand Down Expand Up @@ -68,13 +70,17 @@ public void testIncludes0() {

@Test
public void testMedia0() {
MediaEntityV2 media = tweetList.getIncludes().getMedia().get(0);
MediaEntityV2 media = tweetList.getIncludes().getMedia().get(0);
List<Variant> variants = media.getVariants();
assertEquals("7_1460322142680072196", media.getKey());
assertEquals(900, media.getHeight());
assertEquals("video", media.getType());
assertEquals(11093, media.getDuration());
assertEquals(64061, media.getPublicMetrics().getViewCount());
assertEquals(1600, media.getWidth());
assertNotNull(variants);
assertEquals(2176000, variants.get(0).getBitRate());
assertEquals("https://video.twimg.com/ext_tw_video/1572885321980731394/pu/vid/720x1280/ieIyRb1_aPrsEAwy.mp4?tag=12", variants.get(0).getUrl());
}

@Test
Expand Down
21 changes: 21 additions & 0 deletions src/test/resources/tests/tweet_list_v2_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,27 @@
"public_metrics": {
"view_count": 64061
},
"variants": [
{
"bit_rate": 2176000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1572885321980731394/pu/vid/720x1280/ieIyRb1_aPrsEAwy.mp4?tag=12"
},
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/ext_tw_video/1572885321980731394/pu/pl/Cjl2_HqO6UVWd7ay.m3u8?tag=12&container=fmp4"
},
{
"bit_rate": 632000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1572885321980731394/pu/vid/320x568/WK7e4ol6eVW-fP5x.mp4?tag=12"
},
{
"bit_rate": 950000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1572885321980731394/pu/vid/480x852/23EP3iqOrVLt8BUD.mp4?tag=12"
}
],
"height": 900
},
{
Expand Down