Advertisement
IzaacJ

Get YouTube VideoID from Url

Aug 28th, 2013
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1. private string GetYouTubeVideoID(string lnk)
  2. {
  3.    if (lnk.Contains("youtube.com") ||
  4.        lnk.Contains("youtu.be"))
  5.    {
  6.        Regex YT = new Regex(@"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
  7.        Match youTube = YT.Match(lnk);
  8.        if (youTube.Success)
  9.        {
  10.            _linkType = "youtube";
  11.            return youTube.Groups[1].Value;
  12.        }
  13.        _linkType = "url";
  14.        return lnk;
  15.    }
  16.    _linkType = "url";
  17.    return lnk;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement