[Twitter] Fix Twitter bridge images and add other media types (#1595)

* Keep old URI structure

Use the username, not the user ID.

* Fix Twitter bridge images

Credit to @kinoushe

See https://github.com/RSS-Bridge/rss-bridge/issues/1562#issuecomment-639393175

* Include Videos and "Animated GIF" as twit enclosures

Credit to @kinoushe for digging into the API docs.

https://github.com/RSS-Bridge/rss-bridge/issues/1562#issuecomment-640320688

* Calculate the highest bitrate video

Include that on the enclosure.

* Appease linter

* Appease linter, again

* Remove surrounding link from videos

Add it on a smaller link besides it.

See
https://github.com/RSS-Bridge/rss-bridge/pull/1595#issuecomment-640989208

* Include video poster on the enclosures.
This commit is contained in:
somini 2020-06-10 21:39:36 +01:00 committed by GitHub
parent 98ff5a095c
commit 22a01f1093
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -232,7 +232,7 @@ EOD
$item['avatar'] = $user_info->profile_image_url_https; $item['avatar'] = $user_info->profile_image_url_https;
$item['id'] = $tweet->id_str; $item['id'] = $tweet->id_str;
$item['uri'] = self::URI . $tweet->user_id_str . '/status/' . $item['id']; $item['uri'] = self::URI . $item['username'] . '/status/' . $item['id'];
// extract tweet timestamp // extract tweet timestamp
$item['timestamp'] = $tweet->created_at; $item['timestamp'] = $tweet->created_at;
@ -255,15 +255,17 @@ EOD;
} }
// Get images // Get images
$image_html = ''; $media_html = '';
if(isset($tweet->extended_entities->media) && !$this->getInput('noimg')) { if(isset($tweet->extended_entities->media) && !$this->getInput('noimg')) {
foreach($tweet->extended_entities->media as $media) { foreach($tweet->extended_entities->media as $media) {
$image = $media->media_url_https; switch($media->type) {
$display_image = $media->media_url; case 'photo':
// add enclosures $image = $media->media_url_https . '?name=orig';
$item['enclosures'][] = $image; $display_image = $media->media_url_https;
// add enclosures
$item['enclosures'][] = $image;
$image_html .= <<<EOD $media_html .= <<<EOD
<a href="{$image}"> <a href="{$image}">
<img <img
style="align:top; max-width:558px; border:1px solid black;" style="align:top; max-width:558px; border:1px solid black;"
@ -271,6 +273,39 @@ EOD;
src="{$display_image}" /> src="{$display_image}" />
</a> </a>
EOD; EOD;
break;
case 'video':
case 'animated_gif':
if(isset($media->video_info)) {
$link = $media->expanded_url;
$poster = $media->media_url_https;
$video = null;
$maxBitrate = -1;
foreach($media->video_info->variants as $variant) {
$bitRate = isset($variant->bitrate) ? $variant->bitrate : -100;
if ($bitRate > $maxBitrate) {
$maxBitrate = $bitRate;
$video = $variant->url;
}
}
if(!is_null($video)) {
// add enclosures
$item['enclosures'][] = $video;
$item['enclosures'][] = $poster;
$media_html .= <<<EOD
<a href="{$link}">Video</a>
<video
style="align:top; max-width:558px; border:1px solid black;"
referrerpolicy="no-referrer"
src="{$video}" poster="{$poster}" />
EOD;
}
}
break;
default:
Debug::log('Missing support for media type: ' . $media->type);
}
} }
} }
@ -294,7 +329,7 @@ EOD;
<blockquote>{$cleanedTweet}</blockquote> <blockquote>{$cleanedTweet}</blockquote>
</div> </div>
<div style="display: block; vertical-align: top;"> <div style="display: block; vertical-align: top;">
<blockquote>{$image_html}</blockquote> <blockquote>{$media_html}</blockquote>
</div> </div>
EOD; EOD;