From ec001e721e4c887fb3e738d9659ac3fe470c7ce4 Mon Sep 17 00:00:00 2001 From: MBlyzniukov Date: Mon, 26 Sep 2022 15:33:37 +0300 Subject: [PATCH 1/2] Add Variant media field --- .../github/redouane59/twitter/TwitterClient.java | 2 +- .../redouane59/twitter/dto/tweet/TweetV2.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/redouane59/twitter/TwitterClient.java b/src/main/java/io/github/redouane59/twitter/TwitterClient.java index 99835e1d..8d65d952 100644 --- a/src/main/java/io/github/redouane59/twitter/TwitterClient.java +++ b/src/main/java/io/github/redouane59/twitter/TwitterClient.java @@ -115,7 +115,7 @@ public class TwitterClient implements ITwitterClientV1, ITwitterClientV2, ITwitt 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"; + "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 = diff --git a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java index f8d8a164..d69b6b19 100644 --- a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java +++ b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java @@ -496,6 +496,8 @@ public static class MediaEntityV2 implements MediaEntity { private String previewImageUrl; @JsonProperty("public_metrics") private MediaPublicMetricsDTO publicMetrics; + @JsonProperty("variants") + private List variants; @JsonProperty("alt_text") private String altText; @@ -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; + } } From fb751b0a2ebd407380f4e2a4fac05103dd62315c Mon Sep 17 00:00:00 2001 From: MBlyzniukov Date: Tue, 27 Sep 2022 10:19:29 +0300 Subject: [PATCH 2/2] Add assertion --- .../unit/TweetListDeserializerTest.java | 8 ++++++- .../tests/tweet_list_v2_example.json | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/redouane59/twitter/unit/TweetListDeserializerTest.java b/src/test/java/io/github/redouane59/twitter/unit/TweetListDeserializerTest.java index f6a343a7..6951d7c6 100644 --- a/src/test/java/io/github/redouane59/twitter/unit/TweetListDeserializerTest.java +++ b/src/test/java/io/github/redouane59/twitter/unit/TweetListDeserializerTest.java @@ -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 { @@ -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 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 diff --git a/src/test/resources/tests/tweet_list_v2_example.json b/src/test/resources/tests/tweet_list_v2_example.json index 661da1bc..da1dc62c 100644 --- a/src/test/resources/tests/tweet_list_v2_example.json +++ b/src/test/resources/tests/tweet_list_v2_example.json @@ -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 }, {