This YouTube video contains its own ID

← Back to varun.ch

I created a YouTube video, which contains its own video ID.

https://www.youtube.com/watch?v=4tN9sEMPqxk

Usually, this should not be possible, as the unique video ID is generated after uploading the video, and YouTube provides no way to edit or replace existing videos. [0]

Except — YouTube actually uploads videos in two parts: The metadata (title, description, etc.), and the video itself. This allows creators to setup the video settings while waiting for the video to upload — and it allows us to create funky self referencing videos.

The 2 requests

There is probably a more elegant way to do this, but I found a hacky way to exploit the ordinary upload process to create the self referencing video.

I stuck to YouTube's normal video uploading procedure (in YouTube Studio) and browser DevTools as much as possible to avoid having to reverse engineer too much of the internal API, or pay for Google's public developer API.

First, I created a placeholder video to start the upload with. It needs to have a file size equal to or greater than the final video, otherwise YouTube will reject the upload as incomplete.

I also created the final video, with slots to put the video ID in later. (It is important to prepare this earlier, as YouTube will probably cancel the upload if no video data is uploaded within some timeframe)

My video in the editor

Next, I set up Chrome DevTools to block HTTP requests to https://upload.youtube.com/?authuser=0&upload_id*, which prevents the placeholder video from actually getting sent to YouTube (except for the file size, which is probably part of the metadata request).

Then, I "uploaded" the placeholder video to YouTube, and watched the network logs for the createvideo request. The response includes the videoId.

createvideo response

I quickly rendered the final video, now containing the video ID that YouTube gave me. However, before uploading the video, I needed to make sure that the file size of my placeholder video and final videos matched. I found that I could add garbage data to the end of my mp4 video file to increase the file size without corrupting video playback.

After double checking the file sizes, I copied one of the blocked requests to https://upload.youtube.com/?authuser=0&upload_id=... (for retrying the upload), imported it into Insomnia[1], and replaced the body with my new video file. I sent the request and waited.

Upload request in Insomnia

Finally, I checked the video on YouTube after a few minutes, and it worked!

The video IDs match

Footnotes

  1. That was a lie — Google provides a way for partners to replace videos, for example Apple fixed a mistake in their ad while retaining the same video ID. But the rest of us can't be trusted with such power.
  2. You don't need to use a REST client like Insomnia, Postman or curl (you can do it all in the browser with fetch), but it makes sending the binary file as the request body much easier.