Skip to content

Commit

Permalink
Add lives?part=poll
Browse files Browse the repository at this point in the history
Solving [the Stack Overflow question 78460499](https://stackoverflow.com/q/78460499).
  • Loading branch information
Benjamin-Loison committed May 11, 2024
1 parent d8e89c7 commit e084ef2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lives.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'donations',
'sponsorshipGifts',
'memberships',
'poll',
];

foreach ($realOptions as $realOption) {
Expand Down Expand Up @@ -126,6 +127,29 @@ function cleanMembershipOrSponsorship($raw, $isMembership) {
$item['memberships'] = $memberships;
}

if ($options['poll']) {
$firstAction = $actions[0];
if(array_key_exists('showLiveChatActionPanelAction', $firstAction)) {
$pollRenderer = $firstAction['showLiveChatActionPanelAction']['panelToShow']['liveChatActionPanelRenderer']['contents']['pollRenderer'];
$pollHeaderRenderer = $pollRenderer['header']['pollHeaderRenderer'];
$liveChatPollStateEntity = $result['frameworkUpdates']['entityBatchUpdate']['mutations'][0]['payload']['liveChatPollStateEntity'];
$metadataTextRuns = explode('', $liveChatPollStateEntity['metadataText']['runs'][0]['text']);
$poll = [
'question' => $liveChatPollStateEntity['collapsedMetadataText']['runs'][2]['text'],
'choices' => array_map(fn($choiceText, $choiceRatio) => [
'text' => $choiceText['text']['runs'][0]['text'],
'voteRatio' => $choiceRatio['value']['voteRatio'],
], $pollRenderer['choices'], $liveChatPollStateEntity['pollChoiceStates']),
'channelName' => $metadataTextRuns[0],
'timestamp' => str_replace("\u{00a0}", ' ', $metadataTextRuns[1]),
'totalVotes' => intval(str_replace(' votes', '', $metadataTextRuns[2])),

'channelThumbnails' => $pollHeaderRenderer['thumbnail']['thumbnails'],
];
}
$item['poll'] = $poll;
}

return $item;
}

Expand Down

1 comment on commit e084ef2

@Benjamin-Loison
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #272.

Please sign in to comment.