Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I'm writing code to validate YouTube URLs. Is it guaranteed that the video ID, such as oHg5SJYRHA0, is always exactly 11 characters long, or can it sometimes be shorter or longer? Is there any official documentation about this?

share|improve this question

migrated from stackoverflow.com Mar 26 '11 at 10:36

This question came from our site for professional and enthusiast programmers.

    
At least until 5.20e+19 videos are made ;) –  Jason McCreary Mar 26 '11 at 2:17
    
@Jason damn you! what calculator are you using! –  Saad Mar 26 '11 at 2:23
    
The max. combination in 11 chars seems like a large number, but it wont't be probably enaugh in a few years since the number of uploaded youtube videos grows exponentialy... So do NOT count on that if you are creating not-for-one-year websites. –  jave.web Aug 12 at 16:52
    
@jave.web You're late to the party. I was asking for authoritative sources, not for someone to argue whether 64^11 is a big number. There could be other reasons that some video codes could be different format than running out of them. For example, there might be legacy videos with shorter codes, or videos that are stored in a separate system, with a different code format entirely. The accepted answer contains the most authoritative answer I've seen so far. –  nitro2k01 Aug 15 at 21:51
    
my comment still applies, especially in 2014, and just supports the accepted answer ;) –  jave.web Aug 18 at 21:55

2 Answers 2

up vote 11 down vote accepted

They'll probably stick to 11 chars for a long time. Each character has 64 possible values:

2*26 letters (lowercase and uppercase) + 10 for the digits, + 2 for "_" and "-" chars

2 * 26 + 10 + 2 = 64

Then 11 characters in total:

64^11 = 73786976294838210000 (or more or less "73,7e18")

Of course not all combination will be used, depending on their algorithm, but they are probably not going to change it anytime soon. Words from a YouTube developer state that they do not guarantee, though:

I don't see anywhere in the documentation where we officially commit to a standard length of 11 characters for YouTube video ids. It's one of those things where we have a current implementation, and it may stay that way indefinitely. But we're not offering any official commitment to that, so proceed at your own risk.

A better approach, though one that's more involved, would be to take each video id and make a request to the YouTube API to see if it's valid. E.g., make an HTTP GET to

http://gdata.youtube.com/feeds/api/videos/VIDEO_ID

and see if you get back a HTTP 200 response. Of course, if you take that approach, videos that have been removed from YouTube will come back as invalid (which may or may not be what you want) and videos that have been very recently uploaded to YouTube might also come back as invalid.

Cheers, -Jeff Posnick, YouTube API Team

Source: https://web.archive.org/web/20120306111051/http://osdir.com/ml/youtube-api-gdata/2009-10/msg00237.html

share|improve this answer
    
@Diego: If you're going to cite so many digits, you may as well show the last few: 64^11 = 2^66 = 73,786,976,294,838,206,464 With 0.5 rounding, the engineering form is 73.787e18 . –  user60228 Feb 9 at 21:46

Yes, they always have 11 characters.

share|improve this answer
2  
Do you have any information to back that up? –  Al E. Jun 15 '12 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.