"Most Replayed" Data of YouTube Video via API
Asked Answered
M

2

16

Is there any way to extract the "Most Replayed" (aka Video Activity Graph) Data from a YouTube video via API?

What I'm referring to:

Image of Youtube Video with "Most Replayed" Data displayed

Malo answered 14/6, 2022 at 1:17 Comment(2)
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Stoltz
@Stoltz I'm not sure how many more details I can give :/Malo
C
21

One more time YouTube Data API v3 doesn't provide a basic feature.

I recommend you to try out my open-source YouTube operational API. Indeed by fetching https://yt.lemnoslife.com/videos?part=mostReplayed&id=VIDEO_ID, you will get the most replayed graph values you are looking for in item["mostReplayed"].

With the video id XiCrniLQGYc you would get:

{
    "kind": "youtube#videoListResponse",
    "etag": "NotImplemented",
    "items": [
        {
            "kind": "youtube#video",
            "etag": "NotImplemented",
            "id": "XiCrniLQGYc",
            "mostReplayed": {
                "markers": [
                    {
                        "startMillis": 0,
                        "intensityScoreNormalized": 1
                    },
                    {
                        "startMillis": 2580,
                        "intensityScoreNormalized": 0.7083409245967562
                    },
                    {
                        "startMillis": 5160,
                        "intensityScoreNormalized": 0.6381007317793738
                    },
                    ...
                    {
                        "startMillis": 255420,
                        "intensityScoreNormalized": 0.012864077773078256
                    }
                ],
                "timedMarkerDecorations": [
                    {
                        "visibleTimeRangeStartMillis": 0,
                        "visibleTimeRangeEndMillis": 10320
                    }
                ]
            }
        }
    ]
}
Cadence answered 15/6, 2022 at 0:13 Comment(8)
This looks like it works, but how should I read the page it spits out? For example: yt.lemnoslife.com/videos?part=mostReplayed&id=NIJ5RiMAmNs. How should I read that?Malo
@Malo Look at the "heatMarkerIntensityScoreNormalized" number. 0 is nobody is re-playing and 1 is everybody is replaying.Avidity
@Malo As heatMarkerIntensityScoreNormalized name suggests, I recommend you to learn more about Normalisation.Cadence
I have tried to use this API for finding the most replayed part from the top videos by generating the ID of YouTube's most trending videos using the googleapiclient but when I request the API, it returns the item[mostReplayed] as None. Am I doing something wrong with your API as it has worked very well with IDs that I have just manually retrieved from other YouTube videos.Fontana
@CharlieCook Please provide an example of video id having this issue.Cadence
I generated a list of the most trending videos' ids:Fontana
['l-bGkjtMC0Q', 'OLvRv-poMtA', '4R7vRFGJr3k', 'OBsLKLef-F0', 'ar3gEAT2h28', '6ecTO22ulRM', 'J4-lP_D7iEk', 'ZEuV9d3gsio', 'T4CY4wVqhPU', 'v8tR7mPsBcU']Fontana
@CharlieCook As we discussed on Discord, your first video l-bGkjtMC0Q does not have public most replayed data (see OP highlighted curve example), hence my API cannot retrieve any.Cadence
F
1

Adding the following snippet to parse/read through @Benjamin's API response. This function will give you the top 5 snippets (peaks) from the video.

def get_peak_rewatched_timestamps(test_data):
    markers = test_data['items'][0]['mostReplayed']['markers']
    sorted_markers = sorted(markers, key=lambda x: x['intensityScoreNormalized'], reverse=True)    
    top_markers = sorted_markers[:5]
    top_timestamps_seconds = [marker['startMillis'] / 1000 for marker in top_markers]
    return top_timestamps_seconds
Farthest answered 20/5 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.