Browse Source

support twitter animated gifs

pull/78/head v1.4.35
Aaron Parecki 2 years ago
parent
commit
70f1576926
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 225 additions and 1 deletions
  1. +7
    -1
      lib/XRay/Formats/Twitter.php
  2. +12
    -0
      tests/TwitterTest.php
  3. +206
    -0
      tests/data/api.twitter.com/tweet-with-gif.json

+ 7
- 1
lib/XRay/Formats/Twitter.php View File

@ -183,10 +183,16 @@ class Twitter extends Format {
$entry['photo'][] = $media->media_url_https;
} elseif($media->type == 'video') {
} elseif($media->type == 'video' || $media->type == 'animated_gif') {
if(!array_key_exists('photo', $entry))
$entry['photo'] = [];
if(!array_key_exists('video', $entry))
$entry['video'] = [];
// Include the thumbnail
$entry['photo'][] = $media->media_url_https;
// Find the highest bitrate video that is mp4
$videos = $media->video_info->variants;
$videos = array_filter($videos, function($v) {

+ 12
- 0
tests/TwitterTest.php View File

@ -117,9 +117,21 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Tweet with a video', $data['data']['content']['text']);
$this->assertEquals('https://pbs.twimg.com/ext_tw_video_thumb/818913089248595970/pr/img/qVoEjF03Y41SKpNt.jpg', $data['data']['photo'][0]);
$this->assertEquals('https://video.twimg.com/ext_tw_video/818913089248595970/pr/vid/1280x720/qP-sDx-Q0Hs-ckVv.mp4', $data['data']['video'][0]);
}
public function testTweetWithGif() {
list($url, $json) = $this->loadTweet('tweet-with-gif');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Look! A distraction 🐁', $data['data']['content']['text']);
$this->assertEquals('https://video.twimg.com/tweet_video/DiFOUuYV4AAUsgL.mp4', $data['data']['video'][0]);
$this->assertEquals('https://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg', $data['data']['photo'][0]);
}
public function testTweetWithLocation() {
list($url, $json) = $this->loadTweet('818912506496229376');

+ 206
- 0
tests/data/api.twitter.com/tweet-with-gif.json View File

@ -0,0 +1,206 @@
{
"created_at": "Sat Jul 14 17:11:30 +0000 2018",
"id": 1018181204384731136,
"id_str": "1018181204384731136",
"full_text": "@SwiftOnSecurity Look! A distraction 🐁 https://t.co/MRXk3g3Gvc",
"truncated": false,
"display_text_range": [
17,
38
],
"entities": {
"hashtags": [
],
"symbols": [
],
"user_mentions": [
{
"screen_name": "SwiftOnSecurity",
"name": "SwiftOnSecurity",
"id": 2436389418,
"id_str": "2436389418",
"indices": [
0,
16
]
}
],
"urls": [
],
"media": [
{
"id": 1018181108716920832,
"id_str": "1018181108716920832",
"indices": [
39,
62
],
"media_url": "http://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg",
"media_url_https": "https://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg",
"url": "https://t.co/MRXk3g3Gvc",
"display_url": "pic.twitter.com/MRXk3g3Gvc",
"expanded_url": "https://twitter.com/JenMsft/status/1018181204384731136/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 500,
"h": 210,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 500,
"h": 210,
"resize": "fit"
},
"medium": {
"w": 500,
"h": 210,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 1018181108716920832,
"id_str": "1018181108716920832",
"indices": [
39,
62
],
"media_url": "http://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg",
"media_url_https": "https://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg",
"url": "https://t.co/MRXk3g3Gvc",
"display_url": "pic.twitter.com/MRXk3g3Gvc",
"expanded_url": "https://twitter.com/JenMsft/status/1018181204384731136/photo/1",
"type": "animated_gif",
"sizes": {
"small": {
"w": 500,
"h": 210,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 500,
"h": 210,
"resize": "fit"
},
"medium": {
"w": 500,
"h": 210,
"resize": "fit"
}
},
"video_info": {
"aspect_ratio": [
50,
21
],
"variants": [
{
"bitrate": 0,
"content_type": "video/mp4",
"url": "https://video.twimg.com/tweet_video/DiFOUuYV4AAUsgL.mp4"
}
]
}
}
]
},
"source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
"in_reply_to_status_id": 1018178408398966784,
"in_reply_to_status_id_str": "1018178408398966784",
"in_reply_to_user_id": 2436389418,
"in_reply_to_user_id_str": "2436389418",
"in_reply_to_screen_name": "SwiftOnSecurity",
"user": {
"id": 3309105596,
"id_str": "3309105596",
"name": "Jen Gentleman 🌺",
"screen_name": "JenMsft",
"location": "Seattle, WA",
"description": "Software Engineer, Community Manager & #WindowsInsider on Shell team @ Microsoft. I work w/ Windows feedback 4 Start, Action center, taskbar, Windows Ink + more",
"url": "https://t.co/ACVIR7xvcT",
"entities": {
"url": {
"urls": [
{
"url": "https://t.co/ACVIR7xvcT",
"expanded_url": "https://www.instagram.com/jenmsft/",
"display_url": "instagram.com/jenmsft/",
"indices": [
0,
23
]
}
]
},
"description": {
"urls": [
]
}
},
"protected": false,
"followers_count": 18038,
"friends_count": 224,
"listed_count": 352,
"created_at": "Fri Aug 07 22:21:33 +0000 2015",
"favourites_count": 130904,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 33996,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "1A1B1F",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme9/bg.gif",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme9/bg.gif",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/987773638614048768/_Z7nZCoF_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/987773638614048768/_Z7nZCoF_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/3309105596/1524338784",
"profile_link_color": "CB26D1",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": true,
"has_extended_profile": true,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 25,
"favorite_count": 90,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"possibly_sensitive_appealable": false,
"lang": "en"
}

Loading…
Cancel
Save