Skip to content

Commit

Permalink
Fix #25: Improve mostReplayed endpoint? (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Sep 30, 2023
1 parent 8e4c022 commit fdc0789
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,26 @@ function getItem($id)

if ($options['mostReplayed']) {
$json = getJSONFromHTMLForcingLanguage("https://www.youtube.com/watch?v=$id");
$markersMap = $json['playerOverlays']['playerOverlayRenderer']['decoratedPlayerBarRenderer']['decoratedPlayerBarRenderer']['playerBar']['multiMarkersPlayerBarRenderer']['markersMap'];
$mostReplayed = $markersMap !== null ? end($markersMap)['value']['heatmap']['heatmapRenderer'] : null;
// What is `Dp` in `maxHeightDp` and `minHeightDp` ? If not relevant could add ['heatMarkers'] to the JSON path above.
$mostReplayed = $json['frameworkUpdates']['entityBatchUpdate']['mutations'][0]['payload']['macroMarkersListEntity']['markersList'];
foreach(array_keys($mostReplayed['markers']) as $markerIndex)
{
unset($mostReplayed['markers'][$markerIndex]['durationMillis']);
$mostReplayed['markers'][$markerIndex]['startMillis'] = intval($mostReplayed['markers'][$markerIndex]['startMillis']);
}
$timedMarkerDecorations = $mostReplayed['markersDecoration']['timedMarkerDecorations'];
foreach(array_keys($timedMarkerDecorations) as $timedMarkerDecorationIndex)
{
foreach(['label', 'icon', 'decorationTimeMillis'] as $timedMarkerDecorationKey)
{
unset($timedMarkerDecorations[$timedMarkerDecorationIndex][$timedMarkerDecorationKey]);
}
}
$mostReplayed['timedMarkerDecorations'] = $timedMarkerDecorations;
foreach(['markerType', 'markersMetadata', 'markersDecoration'] as $mostReplayedKey)
{
unset($mostReplayed[$mostReplayedKey]);
}

$item['mostReplayed'] = $mostReplayed;
}

Expand Down

0 comments on commit fdc0789

Please sign in to comment.