Reputation: 168
I've tried playing with YouTube video URL's and found that two every video has two links for example
Suppose a video has the following link
https://www.youtube.com/watch?v=YykjpeuMNEk
Now I change the last letter of the link to make it
https://www.youtube.com/watch?v=YykjpeuMNEl
Try out both the links would open one video.
The logic is change the last letter with the consecutive letter, the letters are case sensitive.
So if the last letter is 'a' change it to 'b', if 'A' change it to 'B', if '1' change it to '2'.
Can someone explain me what is happening in this case?
Upvotes: 3
Views: 4249
Reputation: 5629
This is because YouTube IDs use a variant of Base64, and each Base64 character is pure ASCII, meaning it provides only 6 bits, and the final decoded byte value is a multiple of 8 bits. This inevitably ends up not matching completely, and unless specifically indicated with extra end characters, some of these lowest bits simply have no meaning.
YouTube ID: 6 bits * 11 = 66 bits.
The given data seems to indicate that YouTube video IDs are actually a 64-bit number converted to Base64. Since we have 66 bits, and need only 64, that would mean that the last 2 bits are simply ignored.
When practically applied, this doesn't seem to be completely true, though.
YykjpeuMNEk => k = 1101011
If we were to just ignore the last 2 bits there, then we see k is actually the highest value (ends on 11), and the other ones would be the lower values, namely h, i, and j; respectively 1101000, 1101001 and 1101010. Instead they're l, m and n.
This is probably just due to the way the final value is processed to a 64-bit number, though. The theory still holds true; YouTube IDs are only accurate up to 64 bit, despite being 66-bit Base64 strings.
Meaning, every YouTube URL has not two, but in fact four IDs that match it.
Upvotes: 3