← 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. 
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.
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)
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
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, and replaced the body with my new video file. I sent the request and waited.
Finally, I checked the video on YouTube after a few minutes, and it worked!
fetch), but it makes sending the binary file as the request body much easier.