[YouTubeCommunityTabBridge] Add timestamps (#3477)

As YouTube doesn't provide precise dates for community posts, an
increasing multiple of 60 seconds is subtracted from each timestamp.
This ensures that the original order is always preserved, even if there
are multiple posts with the same date (e.g. "1 month ago").
This commit is contained in:
Thomas 2023-07-02 22:56:08 +02:00 committed by GitHub
parent bf73372d7f
commit eb2b4747ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,7 +78,7 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
returnServerError('Channel does not have a community tab');
}
foreach ($this->getCommunityPosts($json) as $post) {
foreach ($this->getCommunityPosts($json) as $key => $post) {
$this->itemTitle = '';
if (!isset($post->backstagePostThreadRenderer)) {
@ -102,6 +102,12 @@ class YouTubeCommunityTabBridge extends BridgeAbstract
$item['content'] .= $this->getAttachments($details);
$item['title'] = $this->itemTitle;
$date = strtotime(str_replace(' (edited)', '', $details->publishedTimeText->runs[0]->text));
if (is_int($date)) {
// subtract an increasing multiple of 60 seconds to always preserve the original order
$item['timestamp'] = $date - $key * 60;
}
$this->items[] = $item;
}
}